I have a list of say 15 images.
How can I make it so that in each page refresh they all change to a random position?
Thanks
Jump to PostPlace locations into a multidimensional array (positions - X, Y coords).
Place images into an array.
You can use shuffle to shuffle the image arrangement.
Place an image to a position via a loop.
Jump to Postif you do use an array, you could use the shuffle() function to randomly display the images.
Jump to PostAhem...
You can use shuffle to shuffle the image arrangement.
Place locations into a multidimensional array (positions - X, Y coords).
Place images into an array.
You can use shuffle to shuffle the image arrangement.
Place an image to a position via a loop.
if you do use an array, you could use the shuffle() function to randomly display the images.
Ahem...
You can use shuffle to shuffle the image arrangement.
Ok, I'm maybe I should rephrase.
I want to change the order of the images not the physical positions.
Would I still use shuffle?
Depends - are you showing all of them or just one?
If all, use shuffle on the array.
If just one, use mt_rand() too generate a random number between 0 and num photos - 1 and use that in conjunction with your array to get an image. Else you could divide the days of the week/month up between the images, so a diff image shows depending on the day/daynumber.
Yep all of them.
Thanks
Heres the code I used;
<?php
$images=array( "1.gif","2.gif","3.gif","4.gif","5.gif" );
shuffle($images);
for ($i=0;$i<5;++$i)
echo "<img src='$images[$i]'>";
?>
You recon instead of the image names (1.gif etc) I could use the source code, because I need each image to hold a link.
Example:
Instead of 1.gif, <a href=".../contact.html"><img src=".../1.gif"></a>
Would that work?
This doesnt seem to work.
Any ideas on how I can shuffle the images and get them to link to a differnet pages?
You need an array of arrays if you want to link an image to a particular link.
$array = array(array("1.gif","contacts.php),array("2.gif","about.php")...);
Perhaps: http://www.php.net/manual/en/function.shuffle.php#93214
Ok ill have a try
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.