View Full Version : random selection out of MySQL results

09-13-2005, 10:32 AM

I'm trying to do a random selection out of a MySQL query with a specific conditional. Example: I have a table that has an item id and the price for each item. I query for all items over a certain price and it returns a series of ids that fit that criteria. Then I need to randomly choose from these returned ids in order to display a random item with that criteria. Any methods or suggestions on how to specifically implement this would be greatly appreciated!

Thanks, Jay

09-13-2005, 11:15 AM
mysql_query("SELECT product FROM table WHERE id='id_number' ORDER BY RAND() LIMIT 1")

Give that a try