Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Need advice on structuring pagination  RSS feed

Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I am working on a pagination system for my webapp and its causing me alot of headaches at the moment.

The user can view upto 50 records per page. The URL query is like page=1, page=2 etc - To workout the the MIN and MAX values for the mysql LIMIT I multiply the page number by 50 which gives me the MAX amount for the LIMIT, to workout the MIN I minus 50 from the MAX amount. So the query for say page 3 would look something like this:

MAX: 50 x 3 = 150
MIN 150 - 50 = 100
SELECT * FROM table WHERE id='1' LIMIT 100, 150;

Now, I have two problems:

1. The user should be able to view the current set of records he is browsing, e.g. "Viewing 100 of 134 Orders" - How do I workout the current amount of records being viewed ? Iknow how to work out the max, I just use count(*) in mysql.

2. How can I determine whether the previous/next page links should be enabled or disabled ?

Please note that I am trying to avoid using any greedy methods of dealing with this issue (such as caching all the records) because the query is complex and there can potentially be ALOT of data in each table.

Before anyone suggests it, yes I have read the pagination FAQ.

Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your problem.

Can't you store information in a session about the number of records available and the number of the first on the current page?

How are these "previous/next" page links being generated?

Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
global solutions you can do at home or in your backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!