random rows using MySQL's rand()
| From: | Tanat | Date: | Tue, 22 Oct 2002 00:54:05 +0000 |
| Subject: | random rows using MySQL's rand() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-120845@lists.php.net to get a copy of this message | ||
Hi all,
I was trying to use the following query to randomly retrieve a row from
MySQL table.
$query = "SELECT * FROM my_table ORDER BY RAND() LIMIT 1";
This query works fine in MySQL client, access via command-line.
But when using this via PHP, it doesn't retrieve the row randomly for a
small set of records, ie. 3.
Now that I've increased the number of records to 32, it starts to show
random behaviour.
So, just wondering whether this is something I can expect for a table with
only a few records.
Regards,
Tanat