ro6er
Programmer
- Jul 1, 2003
- 76
Is it possible to page through a db offset by ID. For example. A user picks id 56 which is between 30 and 101 and then can go back and forth between these numbers. I can't seem to get my head around it. Here's the code I have been using and not yet changed to include this. Thanks for any help. Roger
Code:
<%
' records per page
recordsonpage = 1
' count all records
allrecords = 0
set rs = conn.Execute("SELECT * FROM photos")
do until rs.EOF
allrecords = allrecords + 1
rs.movenext
loop
' if offset is zero then the first page will be loaded
offset = request.querystring("offset")
if offset = 0 OR offset = "" then
requestrecords = 0
else
requestrecords = requestrecords + offset
end if
' opens database
session("fullname") = request("fullname")
'set rs = conn.Execute("SELECT * FROM Photos where ID = "&session("ident")&"")
set rs = conn.Execute("SELECT * FROM Photos where fullname = '"&session("fullname")&"'")
' reads first records
hiddenrecords = requestrecords
do until hiddenrecords = 0 OR rs.EOF
hiddenrecords = hiddenrecords - 1
rs.movenext
if rs.EOF then
lastrecord = 1
end if
loop
%>
<table cellspacing="2" cellpadding="2" border="1" width="400">
<tr>
<td><% if requestrecords <> 0 then %>
<a href="?offset=<% = requestrecords - recordsonpage %>&fullname=<%=session("fullname")%>">Prev Page</a>
<% else %>
Prev Page
<% end if %></td>
<td><% if lastrecord <> 1 then %>
<a href="?offset=<% = requestrecords + recordsonpage %>&fullname=<%=session("fullname")%>">Next Page</a>
<% else %>
Next Page
<% end if %></td>
</tr>
<tr></tr>
</table>
<table cellspacing="2" cellpadding="2" border="1" width="400">
<%
' prints records in the table
showrecords = recordsonpage
recordcounter = requestrecords
do until showrecords = 0 OR rs.EOF
recordcounter = recordcounter + 1
%>
<tr>
<td><b><% = recordcounter %>
recordcounter</b></td>
<td><% = rs("PhotoName") %></td>
<td><% = rs("ID") %>
ID</td>
</tr>
<%
showrecords = showrecords - 1
rs.movenext
if rs.EOF then
lastrecord = 1
end if
loop
%>
</table>
<p>
<%
' Closes connection
rs.close
Conn.close
%>