RE: Generating a Random Number through database COUNT
Posted: Wed Jan 21, 2004 11:38 am
Im trying to generate a random number between 1 and the number of rows in my table. This random number will then be used to query the same table. The idea is that a new row from the table will be displayed each time the page is viewed or reloaded. Here is the code. Unfortuntly i seem to be getting 0 each time thoug the count is 10. Can anyone tell me what im doing wrong.
$query= mysql_query("select count(*) from gossip where published is not null order by published desc");
$visitcount = mysql_result($query,0);
//generate random number
srand((double)microtime()*1000000);
$number = rand(0,$vistcount);
//use random number to query table
$story_sql=mysql_query("select * from gossip where published is not null and gossip_id ='".$number."' order by published desc");
$query= mysql_query("select count(*) from gossip where published is not null order by published desc");
$visitcount = mysql_result($query,0);
//generate random number
srand((double)microtime()*1000000);
$number = rand(0,$vistcount);
//use random number to query table
$story_sql=mysql_query("select * from gossip where published is not null and gossip_id ='".$number."' order by published desc");