problems with random numbers
| From: | Broder B | Date: | Fri, 01 Dec 2000 00:59:17 +0000 |
| Subject: | problems with random numbers | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-28137@lists.php.net to get a copy of this message | ||
I am trying to three random generated numbers so I can get three diferent queries to my MySQL
database. The problem I have is that sometimes I only get two numbers instead of three, I sense the
problem is that one of the randomized number does not exists in the database. Here is the code,
maybe someone could help me?
srand ((double) microtime() * 1000000);
$randval1 = rand(1, $num_rows);
$randval2 = rand(1, $num_rows);
$randval3 = rand(1, $num_rows);
$rand_text_result = query("SELECT * FROM poems WHERE id=$randval1 or id=$randval2 or
id=$randval3");
while ($row = mysql_fetch_array($rand_text_result)) {
echo $row["id"] . "<br>";
}