PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I limit the number of rows returned?


You will often want to limit the number of rows returned from a database when provided with a query.

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

How do I find the number of rows in a result set?

I am extracting data from a MySQL Database of which one of the data stored is seperated by a comma. For example, step1,go here,step 2,go there,step 3,go back etc etc. I want to know how to split the data at the comma and format it in html. Using the split

How do I group the results of a mysql query?

How do I find the ID of a new row added to a table?

How do I include a conditional in my mysql query?



Custom Search