Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Paging through records
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Paging through records

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


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Topic: Paging through records
    Posted: 29 January 2004 at 12:57pm

I had a paging through records page. I need to make it show only 10 navigational pages (as the records are splitted into about 150 pages) but I could not manage to do this. What I need is to show:

<< Prev | 13 14 15 16 17 18 19 20 21 22 | Next >>

What I have now is:

<%
For i = 1 To allpages
If Cint(Request.Querystring("pn")) = i  Then
   Response.Write "<a href=""shownewsletters.asp?cat="& Request.QueryString("cat") &"&pn=" & i & """>[" &  i & "]</a> "
Else
   Response.Write "<a href=""shownewsletters.asp?cat="& Request.QueryString("cat") &"&pn=" & i & """>" & i & "</a> "
End If
Next
x = (allrecords - 9) Mod 12
%>

I'm sure is quite something easy and I am digging in the wrong direction!

I had to mention that I'm using mySQL as db and it does not suports rs.recordcount, rs.pagesize, rs.absolutepage. And that part is working well, the navigation is giving me headaches.



Edited by zaboss
Cristian Banu
Soft 4 web
Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2004 at 1:05am

For i = Request.QueryString("page") - 5 To Request.QueryString("page") + 5
If i > allpages Then Exit For
If Cint(Request.Querystring("pn")) = i  Then
   Response.Write "<a href=""shownewsletters.asp?cat="& Request.QueryString("cat") &"&pn=" & i & """>[" &  i & "]</a> "
Else
   Response.Write "<a href=""shownewsletters.asp?cat="& Request.QueryString("cat") &"&pn=" & i & """>" & i & "</a> "
End If
Next

That should give you the idea, Request.QueryString("page") should actually be the variable that holds the page you're on. You should calculate if there's more than 5 pages after the page you're on, if there's only 2 then you would have to substract 3 from the initial value on the loop. The code above will actually show 11 pages so that the one you're on will be centered.

FeRnAN
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2004 at 1:56am
Thanks, with a set of ifs puted in right places it worked.
Cristian Banu
Soft 4 web
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2004 at 11:45am
Originally posted by zaboss zaboss wrote:

I had to mention that I'm using mySQL as db and it does not suports rs.recordcount, rs.pagesize, rs.absolutepage. And that part is working well, the navigation is giving me headaches.

Using ADO to page through a record set is easier, but not really the best way to do this.
If you are not using MSSQL, the best method is to dump the recordset into an array using GetRows. From there you can get the number of records [Ubound(arrName,2)+1] and can drop your DB connection freeing those resources.
See here for more info

If you are using MSSQL then a stored procedure is the best way (see here).
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2004 at 1:14pm

Thanks, ljamal, I am familiar with get rows, but in my case it is difficult to use it as I also need to play with the recordset and html-ize it + the code should work with Access/MySQL/SQL Server.

I design apps that work with Access/MySQL/SQL Server so I have to adapt my code to mySQL which is the most restrictive. It seems that with the next version, 4.1 will support sub-queries wich will make life easier. When will be able to use stored procedure, MySQL will become quite competitive.

Cristian Banu
Soft 4 web
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 31 January 2004 at 8:47am
The GetRows method turns the record set into a 2 dimensional array, you can still use the array to produce data driven HTML. I use it on a regular basis. All of LongBox.com uses arrays rather than recordset. GetRows works with Access as well as MSSQL and MySQL.
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.