Problems with rand and arrays

From: Date: Thu, 07 Dec 2000 16:19:39 +0000
Subject: Problems with rand and arrays
Groups: php.general 
Request: Send a blank email to php-general+get-29149@lists.php.net to get a copy of this message
I have some problems with the following code. I want to query my database for three randomly texts every time the script runs. But I keep running in to problems. Sometimes $arrRandRes[0] contains a '0' witch it can't do, since I want to query the database with that number as the ID. Please Help Me!!! $a = 0; srand ((double) microtime() * 1000000); $text_id_result = query("SELECT * FROM poems"); while ($row = mysql_fetch_array($text_id_result)) { $arrRes[$a] = $row["id"]; $a++; } $b = 0; $arrRandRes = array_rand($arrRes, 3); $rand_text_result = query("SELECT text FROM poems WHERE id=$arrRandRes[0] or id=$arrRandRes[1] or id=$arrRandRes[2]"); while ($row = mysql_fetch_array($rand_text_result)) { $random[$b] = $row["text"]; $b++; }

« previous php.general (#29149) next »