Re: Random Access to a Database

From: Date: Thu, 03 Aug 2000 07:01:46 +0000
Subject: Re: Random Access to a Database
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-1509@lists.php.net to get a copy of this message
> I am using MySQL. How would this be possible? In MySQL 3.23, you can do: SELECT * FROM table_name ORDER BY RAND() In previous versions you need to be more resourceful. If you have a auto incrementing index you can do this (untested code) Assuming that your auto_inc field is called id... SELECT *, floor(count(id) * rand(now()) + 1) as rand_id FROM table_nameWHERE id=rand_id You can also do a query that returns the count of the table, use PHP's random functions to generate a random number and then query for that entry in the database. Good Luck! Zak PS - This question is better suited to the PHP-DB mailing list

« previous php.windows (#1509) next »