Jump to content

[SOLVED] php rand w/ ul list


bradkenyon

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.