[nycphp-talk] Using Pagination

Gary Mort bz-gmort at
Thu Aug 23 16:10:24 EDT 2007

PaulCheung wrote:
> I am really sorry to have to ask your help once again, but no matter how
> hard I try I can't seem to understand how pagination works
> I created a MySQL database called "test_db" and then  set up the demo 
> table
> "products". the products.php is just a dummy.
> nate.php is the coding.
> I am trying to paginate through the records one by one.(view each 
> record, in
> this case).

There are 2 kinds of pagination.

One assumes the data is dynamic and could change at any point in time.  
So, for every query you run, you save off a copy of the data to disk and 
use that report for forward and back.

The other kind assumes the data is static(a list of products that is 
rarely updated, for example) and that you don't care about the 
occassional odd case of someone trying to go forward or back and not 
getting what they would expect.

For the latter case,  you just need to know what record you were looking 
at in the table and use the limit command on your SQL.


Start at the first record, give me 1 record

So when they click forward or back, they send row=3 or row=1 assuming 
your on the second row

Than you set $rownum to the row variable, and your query becomes
LIMIT $rownum, 1

The problem with this case is say there are 100 records in the database, 
and the person is on #90
While they are there, you delete record 89 and then they use the 
previous button to load record loads what used to be record 
90(the one they were looking at).

Honestly, it's not elegant, but this is good enough for many situations.

More information about the talk mailing list