PDA

View Full Version : "Pages" of Records...


Morgoth
03-29-2003, 07:07 PM
Hello,

I am trying to figure out the best method of laying out pages for records...

Such as if I were to have a news section where a person can post messages, and to take less space, it will only show 5 records then any other records would have to be on a new page (most likly with a qeurystring ?page=2)
And on page 2, it will show the next 5 records...

Does anyone have a good method for something like this? I have been trying to figure out one for myself, but came up short with problems, and mistakes I didn't understand..

I am going to try more of this, and I will post any results that I come up with...

One method I had but scraped half way through was this:
(As you can see it's only test code)

Dim IntTestCount , PageNumber
PageNumber = Request.QueryString("page")
If PageNumber = "" Then
PageNumber = 1
End If

Do Until oRS.EOF
IntTestCount = IntTestCount + 1
If IntTestCount = 1 Then
Response.Write "<a href=""news.asp?page=1"">1 </a>"
ElseIf IntTestCount = 6 Then
Response.Write "<a href=""news.asp?page=2"">2 </a>"
End If
oRS.MoveNext
Loop
oRS.MoveFirst
IntTestCount = 0

oRS.Move((PageNumber-1)*5)


I have another idea that I am goint o start working on now..

dominicall
03-29-2003, 07:23 PM
What database you using Morgoth - Access or SQL???

Morgoth
03-29-2003, 07:43 PM
Access...


And it seems this is the only code I can use...

PageNumber = Request.QueryString("page") - 1
If PageNumber = -1 Then PageNumber = 0
oRS.Move((PageNumber)*5)


But now..

How am I suppose to find out how many pages there are so I can display links for them...
Hopfully in some sort of a loop so I don't have to add any html manually...

dominicall
03-29-2003, 08:01 PM
OK - here's a link that should tell you everything you need to know...

http://www.source4developers.com/asp/paging.asp

AM having a look for some other stuff but this should pretty much do it for you...

dominicall :D

dominicall
03-29-2003, 08:11 PM
OK - this should do the trick... the link is for part 3 of the 3 articles about using GetRows...

Essentially this moves the data from a recordset to an array that can then be used for paging... it will save a whole load of resource on the server.

If you're ever doing this in SQL Server, give me a shout - I have a great routine that uses dynamic stored procedures and temporary tables that pulls ONLY the records needed for the page, not all the records - speeds it up.

Anyway - here's the link - it's a good article.

http://www.xefteri.com/articles/16jan2003/default.aspx

dominicall :D

Morgoth
03-29-2003, 09:15 PM
Since my database connection is:
("ADODB.Connection")

Is there a different way to count the number of records instead of rs.RecordCount?

If there is no other simple way, I guess I will just have to manually loop it.

Morgoth
03-29-2003, 10:10 PM
Well, thank you, dominicall

I think I got the hang of it, and I know how it works now...

ALL DONE!

dominicall
03-29-2003, 10:11 PM
You could always call the recordset twice...

If the rs.Open below is wrong sorry - I always tend to use the Command Object to open recordsets. You should get the principal though...

First time - just to do a count - then store the value of the count in a variable...strSQL= "SELECT COUNT(*) AS rsCount FROM tbl_TableName WHERE something = something"

rs.Open strSQL, strCon

Dim rsCount: rsCount = rs("rsCount")

strSQL = "The data select statement here"

rs.Open strSQL, strCon

dominicall :D

Morgoth
03-30-2003, 01:54 AM
Well, I think I got what I needed from this thread...

Thank you all.