Jump to content

Recommended Posts

I'm trying to build pagination into list results of my web app.  However, i'm not too sure how to handle the query. Obviously i need to know the total number of records in order to paginate, but i obviously don't need to capture all records per page.  In other words, if i have 5000 records and i'm showing only 20 per page shouldn't i just query for the 20 i want to display?  How do i do that and still get the count of the 5000 total?

Link to comment
https://forums.phpfreaks.com/topic/39836-efficient-queries-for-pagination/
Share on other sites

Well, SQL_CALC_FOUND_ROWS can work for your first LIMIT 0,20 -- however, a LIMIT 4800,20 means you're throwing away 4800 records! If you're doing this a lot, and the order doesn't change, you may want to consider "ranking" them temporarily somewhere and then ordering based on WHERE clauses.

Thanks fenway, that pretty much confirms what i was worried about. I might look into the temporary ranking solution. Is that easily implemented?  I also found references to using cursors in my googling.  I have zero experience with this and my ISP is running 4.1x so i'm not sure if it's even supported? Anyone have any thoughts on the following links?  They're both for ASP (and I'm assuming SQL server) but maybe the concept could work in MySQL? Beeing a novice it's all over my head...

 

http://aspadvice.com/blogs/jlovell/archive/2004/09/15/1992.aspx

 

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50945

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.