At 05:08 PM 5/22/2004, you wrote:
Robb Kerr wrote:

Got a simple table that contains records which are made up of only three
fields - ID, quote and author. These are "inspirational" quotes that I want
to appear at the bottom of the pages of my website. I want them to come up
randomly with every page load. How do I randomly access records from a
table?

SELECT ID,quote,author from quotes ORDER BY RAND() LIMIT 1

HTH!
--

Unfortunately that will sort the entire table even though it returns only 1 row so it may be too slow for a website if there are a lot of rows in the table.
You will need to create an indexed autoinc field field (if you don't already have one) and use PHP's Math.Random function to pick a single row from the table. The table's autoinc sequence should not have any holes in it. See http://www.phpfreaks.com/quickcode/Random_numbers/87.php for a PHP example on how to use Random.


Mike


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to