Reputation: 1773
I have a database with 16000 rows. I want to grab a random 400 rows.
How would I accomplish this task? Would I do it in Sql? Or select all 16000 rows and then dump a random 400 into an array?
I'm new to PHP and programming..
Thanks for any help.
$result = mysql_query ('SELECT * FROM AllImages') or die ('Error query: '.mysql_error ());
Upvotes: 1
Views: 72
Reputation: 126
you can try this:
$result = mysql_query ('SELECT * FROM AllImages ORDER BY RAND() LIMIT 400');
although it's not very well performing solution if you have a lot of rows
Upvotes: 1
Reputation: 11477
SELECT ... ORDER BY RAND() LIMIT 400
Also, mysql_*
is deprecated.
Upvotes: 3