Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 19th, 2008, 09:32 PM
Authorized User
 
Join Date: Feb 2008
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default asp/Access recordset navigation query

I'm trying to set up a way to navigate through recordsets at 4-6 records per page. I want to simply present url links on the page after the 4-6 records have been shown, so that the next iteration of the loop continues off from where the previous one stopped. at the moment I've just got the data going straight to the page (with some div formatting) and using a rs.movenext within the WHILE NOT rs.EOF ... WEND loop with the result being that ALL the records that match my SQL query will be printed to the page.

Anyone got ideas/suggestions for robust methods?



Thanks in advance,



murshed

 
Old April 10th, 2008, 01:43 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

There are several ways of doing this. One method is to pass a variable back to the same page that returns your results with the page number such as. .

getresults.asp?pn=2 (where getresults.asp contains the results and pn equals your page number.)
multiply pn by the number of results you want to display.

In your WHILE NOT rs.EOF ... WEND loop count the records returned by adding 1 to the variable after movenext. Add a conditional to check to see if the variable falls on the page. Once all the results of that page have been retrieved Use Exit While to end the loop.

such as:
Code:
<%
PageNumber=request.querystring("pn")
if PageNumber = 0 then
  PageNumber=1
end if
NoPerPage=4 ' number of record per page
RecordMin=(((PageNumber-1) * NoPerPage)+1) 'starting number of results
if RecordMin < 1 then
 RecordMin=1
end if
RecordMax=PageNumber * NoPerPage 'ending number of results
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath)
Set objRS = CreateObject("ADODB.Recordset")
objRS.Open sSQL, oConn
RC=1
do while not objRS.EOF
  if RC >= RecordMin and RC <= RecordMax then
    %><% 'Display your results here
  end if
  objRS.movenext
  RC=RC+1
  if RC > RecordMax then
    exit do
  end if
loop

'put page links here
if PageNumber > 1 then
%>
<a href="results.asp?pn=<%=PageNumber-1%>">&lt;&lt;Prev</a>
<%
End if
if not objRS.EOF
%>
<a href="results.asp?pn=<%=PageNumber+1%>">Next&gt;&gt;</a>
<%
End if
objRS.close
oConn.close
set objRS = nothing
set oConn = nothing
%>


The Following User Says Thank You to Frye-Guy For This Useful Post:
murshed (January 16th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Running an Access Query from ASP arholly Access ASP 0 January 25th, 2008 03:31 PM
Recordset Pagination (ASP Access) darinsee Classic ASP Databases 9 September 24th, 2004 05:30 PM
MS Access Query using sql/asp redhorse SQL Language 8 March 17th, 2004 05:15 AM
recordset navigation bar... joeore PHP Databases 2 March 4th, 2004 05:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.