Lasso Soft Inc. > Home

  • Articles

SQL Rows by Page Number

Retrieve all rows for a givenpage number using LIMIT within a -sql inline.

When displaying search results from a -sql inline, it's often helpful to limit the number of hits, such as 10 per page. In order to grab the correct rows for each page, you must use LIMIT.

The formula for LIMIT, given a page number P where P={1,2,3,...,n} and R where R is the number of rows per page is:

   LIMIT (P-1)*R, R


So for example, say your pages each show 10 rows (R=10). Then the above formula would yield:

   Page 1 = LIMIT 0, 10
   Page 2 = LIMIT 10, 10
   Page 3 = LIMIT 20, 10
   ...etc...


More about LIMIT is here:

http://dev.mysql.com/doc/refman/5.1/en/select.html#id2906834

Author: Bil Corry
Created: 18 Feb 2008
Last Modified: 3 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft