I found this simple code so that I can have a random image inserted into a div every time the page is loaded up. http://www.dyn-web.com/code/basics/random_image/random_img_php.php ..and it works great... now, how can I have it do the same thing to multiple divs? coz right now obviously it's loading the same image in every div. I'm totally new to php so please bear with me. Thanks.
Just define this once on your page: $imgList = getImagesFromDir($root . $path); PHP: and use this for image element anywhere? <img src="<?php echo $path . getRandomFromArray($imgList); ?>" alt="" /> PHP:
Thanks, that fixed that problem. Thing is that sometimes there still will be duplicates. I wold like to have the 4 divs all load different images. Any code for that? Thanks for your time.
You're welcome I haven't tested this, but logically... you may want to shuffle() the array $imgList first. Then, array_pop() an array-element really out of the array ( this replaces the previous getRandomFromArray() ). Careful though that you need to limit number of image-elements to be less than available image-files. Hendra
I appreciate your time mate but thats way too technical for me. I tried to look up shuffle and pop a bit but I dont really know how and were to insert any of the code.
Ah, What's so dangerous about some little experimentation of your own? Like before, call this once: $imgList = getImagesFromDir($root . $path); shuffle($imgList); PHP: Then for image-elements use the following: <img src="<?php echo $path . array_pop($imgList); ?>" alt="" /> PHP:
I did try a few stuff but nothing worked. Anyway your code worked perfectly mate, really appreciate your help. thanks alot