bradkenyon Posted June 4, 2008 Share Posted June 4, 2008 i rotate a set of photos, 11 to be exact. below is the code i use to make it work, besides the js file that makes the files rotate, but the code below displays 11 lines, photo1.jpg, photo2.jpg, ... photo11.jpg the problem i have is, i want to make the photos to be in random order, so i was thinking i could use the rand() function to list all 11 photos, but in a different order each time, what do you think is the best way to do it? <ul id="crossfadehomepage"> <? $i=1; while($i <= 11) { print '<li><img src="/crossfade/header/photo'.$i.'.jpg" /></li>'; $i++; } ?> </ul> Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 4, 2008 Share Posted June 4, 2008 Don't use short tags <ul id="crossfadehomepage"> <?php $img_indexes = range(1,11); //Create an array from 1 to 11 shuffle($img_indexes); //Shuffle (randomize) the array foreach($img_indexes as $index) { print '<li><img src="/crossfade/header/photo'.$index.'.jpg" /></li>'; } ?> </ul> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.