来自查询的随机项目

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 ());

SELECT * FROM AllImages order by RAND() limit 400

SELECT ... ORDER BY RAND() LIMIT 400

Also, mysql_* is deprecated.

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