Log in

View Full Version : Random Content Script?



twells22
11-27-2007, 07:22 AM
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?

jc_gmk
11-27-2007, 10:27 AM
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:


$text_array = file('content.txt'); // This gets each line from the text file and holds it in an array

$text = $text_array[rand(0, count($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.

<div>
<? print $text; ?>
</div>

You can also use random MySQL queries in a similar way to this, but this should get you started.

ddadmin
11-28-2007, 01:52 AM
Client side wise, this script probably will do what you need: http://javascriptkit.com/script/script2/randomcontent.shtml