ASP/SQL: Calculate Page of Record

liunx

Guest
Hi!

I am working on a small app that displays information stored in a database (Access), 20 items per page.

My problem is that I would like is if I link to a specific record (for example "default.asp?ticket=25") I want the app to calculate the page of the record and redirect to "default.asp?page=2#25".

Anyone got ideas?
Thanks!

(Here are the columns of the table):

TICKET_ID
TICKET_MSG
CLIENT_ID///*** got something in testing....will put something out here soon ***///

sorry, just really busy at the momentYou can do this easily with

rs.GetRows(start,count)<%
intPaging = 25
sql = "SELECT ID,FIRSTNAME,LASTNAME FROM EMPLOYEES"
set rs = db.execute(sql)

if not(rs.eof) then
arrRS = rs.getRows
intStartPage = -1

for i=0 to ubound(arrRS,2)
if i mod intPaging = 0 then
intStartPage = intStartPage + 1
end if

if arrRS(0,i) = request("ID") then
i = ubound(arrRS,2)
end if
next

intMax = ubound(arrRS,2)

if (intStartPage*intPaging)+intPaging < intMax then
intMax = (intStartPage*intPaging)+intPaging
end if

for i=(intStartPage * intPaging) to intMax
response.write(arrRS(1,i) & " " & arrRS(2,i) & "<BR>")
next
end if
%>


The theory here is to query the entire table because you need to know how many pages are possible (even though you're only going to show 1). Once you have all the records, use the getRows to get an array (arrRS) that's a multi-dimensional array equivalent of the recordset.

Once you have that, you can cycle through it continually searching for the ID value you are looking for. While you're searching, you'll want to keep track of which page you're currently "on" (intStartPage) and for this you'll need to know how many records to a page (intPaging)

Once you've found the record you're looking for and know which page it's on, you have to start at the first record for that page and show the proper number of records (intPaging)

Your code will obviously look different depending on how you do your paging.Great, this helps a lot, thank you! :)
 
Back
Top