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> Link to comment https://forums.phpfreaks.com/topic/108726-solved-php-rand-w-ul-list/ 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> Link to comment https://forums.phpfreaks.com/topic/108726-solved-php-rand-w-ul-list/#findComment-557553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.