Reputation: 471
I wanted to randomly select results from mysql database with this code:
$data = mysql_query("SELECT * FROM people ORDER BY RANDOM() LIMIT 4") or die(mysql_error());
I got an error message: FUNCTION members.RANDOM does not exist
Is there something I'm not adding or doing right here?
Thanks for your asistance.
Upvotes: 7
Views: 5639
Reputation: 14048
This is a very good source of advice for efficiently retrieving random records from a table with MySQL.
http://www.dasprids.de/blog/2008/06/07/fetching-random-rows-of-mysql-efficiently
You might want to check it out.
Upvotes: 1
Reputation: 270775
You need ORDER BY RAND()
$data = mysql_query("SELECT * FROM people ORDER BY RAND() LIMIT 4") or die(mysql_error());
Upvotes: 8