MySQL Data - Best way to implement paging?

Viewed 321582

My iPhone application connects to my PHP web service to retrieve data from a MySQL database, a request can return up to 500 results.

What is the best way to implement paging and retrieve 20 items at a time?

Let's say I receive the first 20 entries from my database, how can I now request the next 20 entries?

7 Answers

Define OFFSET for the query. For example

page 1 - (records 01-10): offset = 0, limit=10;

page 2 - (records 11-20) offset = 10, limit =10;

and use the following query :

SELECT column FROM table LIMIT {someLimit} OFFSET {someOffset};

example for page 2:

SELECT column FROM table
LIMIT 10 OFFSET 10;
Related