View Single Post
Old 06-25-2007   #1 (permalink)
basicwe
Steven
 
Join Date: Jun 2005
Location: McAlester, OKlahaoma - United States
Posts: 21

Randomizing a MYSQL Result

(I know this is a very odd request)
If I wanted to display random information from a database I'd write something like the code below.

PHP Code:
<? 
$cnx 
mysql_connect("localhost""root"""); 
mysql_select_db("entire"$cnx); 
$sql mysql_query("SELECT table FROM entire") or die (mysql_error()); 
while(
$row mysql_fetch_array($sql)){ 
    
$row_array[] = $row['row']; 

mysql_close($cnx); 
$random_row $row_array[rand(0count($row_array) - 1)]; 
echo 
$random_row
?>
----------------------------------
What I'm wondering is if it is possible to determine how long the random information is displayed? I was wondering if it were possible to set a specific ammount of time, and display the database information for that set time?

For example, if I wanted to randomly pull out information using the code above is there any way I'd be able to let it be displayed for 24 hours?

And as a bonus I was wondering if there is a way to not let the same piece of information be displayed twice until all of the other information in the database has been displayed once?

If anyone has any tips, or php functions that may be of any use I'd be very glad to hear them.


Thanks.
basicwe is offline