Results 1 to 4 of 4

Thread: random ordered lists

  1. #1
    Join Date
    Aug 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default random ordered lists

    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In what language?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Code:
    <?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>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •