Print Page | Close Window

Paging through records

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=9362
Printed Date: 01 April 2026 at 1:00am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Paging through records
Posted By: zaboss
Subject: Paging through records
Date 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.



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web



Replies:
Posted By: fernan82
Date 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
http://www.danasoft.com/">


Posted By: zaboss
Date Posted: 30 January 2004 at 1:56am
Thanks, with a set of ifs puted in right places it worked.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: ljamal
Date 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 http://www.4guysfromrolla.com/webtech/070500-1.shtml - here for more info

If you are using MSSQL then a stored procedure is the best way (see http://www.4guysfromrolla.com/webtech/062899-1.shtml - here ).

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: zaboss
Date 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
http://www.soft4web.ro - Soft 4 web


Posted By: ljamal
Date 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.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net