Log in

View Full Version : random ordered lists



abcdefGARY
05-05-2007, 10:04 PM
hi, does anyone know of a script that can generate a random ordered list?

for example...

<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>

rather than having them display the same order, I'd like to be able to put them in random order everytime someone refreshes the page.

I've only been able to find "random content generation", which only displays one of the items in random order.

thanks.

Twey
05-05-2007, 10:09 PM
In what language?

abcdefGARY
05-05-2007, 10:24 PM
I like using javascript because I can actually use html and it should automatically randomize the items from the list ID.

otherwise, PHP is fine, but I hate dealing with all that code. like echo 'sdlkdlfksld' etc.

Twey
05-05-2007, 11:31 PM
PHP's easier in this case and preferable if possible. Performing the effect server-side will ensure that it reaches the greatest number of users.
<?php
$items = array(
'item 1',
'item 2',
'item 3'
);
$items = usort($items, create_function('$a,$b', 'return rand(-1, 1);'));
?>
<ul>
<?php foreach($items as $item) { ?>
<li><?php print $item; ?></li>
<?php } ?>
</ul>