...

View Full Version : next and previous.



phill_ridout
07-02-2007, 04:10 PM
i want to create a search resualts page that will draw the data from a query in an access database. there will be many resualts so i will need to implement previous and next buttons. i cant find any tutorials. is there a db command tht could b usefull? what would be the most efficiant way to do this, so tht the database connection is kept as short as possible? cheers.

miranda
07-02-2007, 06:49 PM
there are many examples of database recordset paging on the web. If you do a search of this forum you will find a number of results also




Here is a link where I provided some code to help someone to page their recordset (http://www.codingforums.com/showthread.php?t=59806)

phill_ridout
07-02-2007, 06:53 PM
it may help me find something, knowing the proper name ;-)

as the the database part, is it more efficiant to access just say 20 resualts at a time, or can i access the whole lot, and store them somewhere so i dont have to keep accsing the db when the user clicks next?

miranda
07-02-2007, 07:24 PM
you could do that. Just use the GetRows() method to put your data into an Array. Then in your for loop use a variable that is contained in the click of the arrow to jump to the next 20 records .

Your asp code might look something like this


sSQL = "SELECT * FROM MyDB"
oRs.Open sSQL, myDSN
If Not oRs.EOF Then
myArray = oRs.GetRows()
HasRecords = True
Else
HasRecords = False
End If

If HasRecords = True Then
If Len(Request("lowerlimit")) = 0 Then
BeginPoint = 0
Else
BeginPoint = Request("lowerlimit")
End If

If Len(Request("upperlimit")) = 0 Then
If Ubound(myArray,2) < 19 Then
EndPoint = Ubound(myArray,2)
Else
EndPoint = 19
End If
Else
EndPoint = Request("upperlimit")
End If

For iRows = BeginPoint to EndPoint
Response.Write "<tr><td>" & myArray(0,iRows) & </td>"
Response.Write "<td>" & myArray(1,iRows) & </td>"
Response.Write "<td>" & myArray(2,iRows) & </td>"
Response.Write "<td>" & myArray(3,iRows) & </td></tr>"
Next
Else
Response.Write "No Records"
End If

phill_ridout
07-02-2007, 08:18 PM
that cool, i dont think there is, but is there any way to keep that array over several pages?

miranda
07-02-2007, 09:31 PM
I haven't tried putting an array into a session variable but it may be possible. I don't know why you would want to do it though. You are much better off making a call to the db to fill the array on a page by page basis. there is much less overhead involved. On an example with recordset paging, it is actually only 1 page of code with the page posting back to itself. you could even do it with ajax displaying the data



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum