How do I limit the number of rows returned?
Most often this is to reduce the amount of material returned, speed things up and make it useable via the web.
Often with paginated queries - e.g. 50, next 50, back 50 and so on this is also a technique you will see used.
It's easily done using the LIMIT structure with mysql which are then past an optional minimum and necessary max number of rows to return.
Thus to return 50 rows, do this:
<?php
$q = mysql_query("SELECT * FROM table LIMIT 50");
?>
If you want to return 20 rows starting at row 10, include the min part like so:
<?php
$q = mysql_query("SELECT * FROM table LIMIT 10,20);
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More mysql PHP Questions
What is difference between mysql_fetch_array and mysql_fetch_object?How do I group the results of a mysql query?
How do I return the date with mySQL?
the uploading status shows success but not showing in the server is empty the written php file is first gave warning cannot uploaded warning in foreach loop but i corrected mistake by keeping above if condition and no error status shows success upload b
How do I find the number of rows affected by a query?
