Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - MySQL recordset paging logic
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MySQL recordset paging logic

 Post Reply Post Reply
Author
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Topic: MySQL recordset paging logic
    Posted: 11 August 2005 at 7:36am
I have developed a routine in ASP to page through a recordset in a MySQL database using MyODBC driver, it works fine, currently like this:

[First|Prev] 1 2 3 4 5 6 [Next|Last]

However if I set to show 1 (one) record per page and if I have 100's of records, the numeric links just add up to the total number of records, making the paging area a massive set of numeric links.

What I want is for it to calculate a few links around the current page then in btw add something, like this:

[First|Prev] 1 2 3 ... 97 98 99 [Next|Last]

Does anyone knows the logic behind this? Looked everywhere, nothing, lots of info on it for ADO and paging for Access/MSSQL but MySQL driver does not support it.
Back to Top
Meson View Drop Down
Newbie
Newbie
Avatar

Joined: 03 June 2003
Location: United States
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote Meson Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2005 at 6:07pm
MySQL paging command is LIMIT.
 
LIMIT starting_record, page_size
 
 
That's it. You have to use your application language (this case ASP) to do anything else. ASP has to set both the starting record and the page size. That means your page list links must post the appropriate numbers back to the application, so that the query can be resubmitted with the updated LIMIT.
 
The logic:
 
retrieve and set the page size and starting record of the page.
 
update the sql statement's LIMIT clause with the new info.
 
Requery MySQL
 
Read out the current page.
 
Build the previous and next links with the appropriate new starting record and page size as querystrings (or post data if using a form)
 
Repeat
 


Edited by Meson - 23 August 2005 at 6:08pm
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2005 at 3:55am
Hi, I have a working routine that does just that.
As it stands it does this:

[Prev] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [Next]

Viewing page 12 -----------------------^^

It has 25 pages, each page shows 10 records, now I don't want all those links showing, my original question was, how to make it so it will show something like this:

[Prev] 1 2 3 ... 10 11 12 13 14 ... 23 24 25 [Next]

Viewing page 12 -----------^^

Note that its nice to contain some initial pages, then also some around the currently viewed page, and at last a few of the last pages, the middle area should change dynamically as we navigate.

What's the code logic behind this? Pseudo or real code examples welcome.

I can post my working code, at this point I just want to understand the working logic so I can test around it.
Back to Top
Meson View Drop Down
Newbie
Newbie
Avatar

Joined: 03 June 2003
Location: United States
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote Meson Quote  Post ReplyReply Direct Link To This Post Posted: 13 September 2005 at 6:54am
You have to implement it in asp. I have no idea how to do it.
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 13 September 2005 at 11:55am
Well, yes, in ASP, but the logic would probably be the same for other languanges.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.