Results 1 to 3 of 3

Thread: Random Content Script?

  1. #1
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random Content Script?

    I want something like "Random Content Order script" but I don't want all the items to be displayed on the page. I just want a single block of html that randomizes every time the page is loaded. Is there something for that here?

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    I know you can do this with php:

    The basic way to do this is to create a text file with the text you want randomized (call it content.txt). Split each block of text with a line break.

    Then use the following php:
    PHP Code:
    $text_array file('content.txt'); // This gets each line from the text file and holds it in an array

    $text $text_array[rand(0count($text_array) - 1)]; // This gets the random content

    $text trim($text); // Trims extra whitespace 
    Then print the $text variable into the html block e.g.
    HTML Code:
    <div>
    <? print $text; ?>
    </div>
    You can also use random MySQL queries in a similar way to this, but this should get you started.
    Last edited by jc_gmk; 11-27-2007 at 10:36 AM.

  3. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Client side wise, this script probably will do what you need: http://javascriptkit.com/script/scri...mcontent.shtml

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
  •