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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.