RE: [PHP-DEV] Random Row From Database
| From: | Chris Newbill | Date: | Sun, 11 Nov 2001 05:17:50 +0000 |
| Subject: | RE: [PHP-DEV] Random Row From Database | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-70063@lists.php.net to get a copy of this message | ||
PHP-Dev is not the list for these questions.
You should read the MySQL manual. (assuming your using MySQL)
Your query should be
SELECT * FROM TABLENAME ORDER BY RAND() LIMIT 1
-Chris
-----Original Message-----
From: HEW Staff [mailto:hewweb@hardiman-e-worldwide.com]
Sent: Saturday, November 10, 2001 9:19 PM
To: php-db@lists.php.net; php-dev@lists.php.net;
php-general@lists.php.net
Subject: [PHP-DEV] Random Row From Database
Hi,
I'm trying to pull a random row from my database and display the contents.
I know that the code:
SELECT * FROM TABLENAME WHERE RAND() LIMIT 1
should work.
However, there are 19 rows in the database and only the first row ever shows
up.
Is there a way to do this to ensure uniqueness?
The code I am using at the moment also filters so that rows are pulled from
the database given certain other criteria such as:
SELECT * FROM TABLENAME WHERE PayerID=$id AND RAND() LIMIT 1
All of the rows in the database contain the same PayerID and this column is
not the Primary Key.
Any help much appreciated.
Jonathan S Hardiman
President/CEO
Hardiman Enterprises Worldwide
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
For additional commands, e-mail: php-dev-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net