note 3557 deleted from rand by hholzgra

From: Date: Fri, 25 Aug 2000 10:40:02 +0000
Subject: note 3557 deleted from rand by hholzgra
Groups: php.notes 
Request: Send a blank email to php-notes+get-3230@lists.php.net to get a copy of this message
Seeding the random number is definately required. If you want to pull a random record from a MySQL database try the following it worked for me on www.miester.org for my quotes database. <?php //remember to connect to you DB as usual $sql = "SELECT * FROM table"; $result = mysql_query($sql); //return number of records $nums = mysql_num_rows($result); //seed the random number srand((double)microtime()*1000000); $random = rand(5,15); //now select the random record $sql = "SELECT * FROM table WHERE id='$random'"; $result = mysql_query($sql); //bring random record into $myrow array $myrow = mysql_fetch_array($result); //now just echo it using $myrow[] pattern ?>

« previous php.notes (#3230) next »