Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Paging through recordset

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,2446
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Paging through recordset
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Paging through recordset - 3/23/2005 5:49:12 AM   
  zahid_a

 

Posts: 14
Score: 0
Joined: 2/16/2005
From: Canada
Status: offline
hi...
i have this script and its giving me problems when i try to page through the database. i cant figure out; as to why its not passing the parameter onto the next page when i click on NEXT...
when i click on NEXT it displays the complete database; as if not reading the parameter provided (if its being provided)...but it gives correct results on the first page....any help will be much appreciated....

thanks a lot.. and here is my code...

<% OPTION EXPLICIT %>
<!-- #INCLUDE FILE ='connection.asp' -->
<!-- METADATA TYPE = "typelib"
FILE = "C:\Program Files\Common Files\System\ado\msado15.dll" -->


<html>
<head>
<title> AUTHOR SEARCH </title>
</head>
<body>

<%

Dim objRS, AUTHOR, nPage, nPageCount, strSQL


AUTHOR = Request.Form("AUTHOR")
AUTHOR = Replace(AUTHOR, "'", "''")

strSQL = "SELECT CallNumber, Author, Title, Series, Edition, Publisher, Date, ISBN, Description, Subject, Notes FROM nova WHERE Author LIKE '%" & AUTHOR & "%' ORDER BY Author"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.PageSize = 10
objRS.CacheSize = 10
objRS.CursorLocation = adUseClient
objRS.Open strSQL, Conn, adOpenStatic


If objRS.EOF Then
Response.Write "No Results Found"
Else

nPageCount = objRS.PageCount
Response.Write "There are: " & "<b>" & nPageCount & "</b>" & " pages." & "<br>"
Response.Write "<b>" & objRS.RecordCount & "</b>" & " records found."
Response.Write "<br>" & "<hr>"

nPage = CLng(Request.QueryString("Page"))

If nPage < 1 OR nPage > nPageCount Then
nPage = 1
Else
End If

objRS.AbsolutePage = nPage

Do While Not (objRS.EOF OR objRS.AbsolutePage <>nPage)


Response.Write "<B>" & "Call Number: " & "</b>" & objRS("CallNumber") & "<BR>"

Response.Write "<B>" & "Author: " & "</b>" & objRS("Author") & "<BR>"

Response.Write "<B>" & "Title: " & "</b>" & objRS("Title") & "<BR>"

Response.Write "<B>" & "Series: " & "</b>" & objRS("Series") & "<BR>"

Response.Write "<B>" & "Edition: " & "</b>" & objRS("Edition") & "<BR>"

Response.Write "<B>" & "Publisher: " & "</b>" & objRS("Publisher") & "<BR>"

Response.Write "<B>" & "Date: " & "</b>" & objRS("Date") & "<BR>"

Response.Write "<B>" & "ISBN: " & "</b>" & objRS("ISBN") & "<BR>"

Response.Write "<B>" & "Description: " & "</b>" & objRS("Description") & "<BR>"

Response.Write "<B>" & "Subject: " & "</b>" & objRS("Subject") & "<BR>"

Response.Write "<B>" & "Notes: " & "</b>" & objRS("Notes") & "<BR>"

Response.Write "<hr>"
objRS.MoveNext
Loop

Response.Write "<div align=""center"">" & vbcrlf


' First page
If objRS.PageCount = 1 Then
Response.Write "<span style=""color:silver;"">First Page</span>"
Response.Write " | "
Else
Response.Write "<A HREF=""authorcode.asp?AUTHOR=" & AUTHOR & "&Page=1"">First Page</A> "
Response.Write " | "
End If


' Previous page:
If objRS.PageCount = 1 OR nPage = 1 Then
Response.Write "<span style=""color:silver;"">Previous Page</span>"
Response.Write " | "
Else
Response.Write "<A HREF=""authorcode.asp?AUTHOR=" & AUTHOR & "&Page=" & nPage - 1 & """>Previous Page</A> "
Response.Write " | "
End If


' Next page
If objRS.PageCount = 1 OR nPage = nPageCount Then
Response.Write "<span style=""color:silver;"">Next Page</span>"
Response.Write " | "
Else
Response.Write "<A HREF=""authorcode.asp?AUTHOR=" & AUTHOR & "&Page=" & nPage + 1 &""">Next Page</A> "
Response.Write " | "
End If


' Last page
If objRS.PageCount = 1 Then
Response.Write "<span style=""color:silver;"">Last Page</span>"
Response.Write " | "
Else
Response.Write "<A HREF=""authorcode.asp?AUTHOR=" & AUTHOR & "&Page=" & nPageCount & """>Last Page</A> "
Response.Write " | "
Response.Write "</div>"
End If

End If



objRS.Close
Set objRS = Nothing


%>

</body>
</html>

_____________________________

zahid
 
 
Post #: 1
 
 Re: Paging through recordset - 4/1/2005 6:52:47 AM   
  larryw24

 

Posts: 8
Score: 0
Joined: 4/1/2005
From: USA
Status: offline
If the Author Name has a space in it, the URL you form with

authorcode.asp?AUTHOR=" & AUTHOR & "&Page=" & nPage + 1

will have a space in it. That space will end the processing of the URL, and the "&Page=" will be ignored.

You need to encode the author name so there is no space. VBScript provides a subroutine that does that encoding.

For example:
Server.URLEncode("Lincoln, Abraham")
produces
Lincoln%2C+Abraham

which CAN be passed in a URL.

Instead of
& AUTHOR &
I suggest you use the following, to discard leading and trailing spaces (if any) as well.
& Server.URLEncode(trim(AUTHOR)) &

(in reply to zahid_a)
 
 
Post #: 2
 
 Re: Paging through recordset - 4/5/2005 5:39:11 AM   
  VBS

 

Posts: 110
Score: 0
Joined: 3/2/2005
From: Lebanon
Status: offline
Dear zahid_a,
I had this problem a lot so i programmed this code my self, it will do the same as the Paging through recordset, but manually,:


      

to use it: follow these simple instructions

1. this code will only show 10 records in each page, to change it, simply change the number 10 to the number u want...

2. to show the number of pages simply use this code

      

3. to surf through pages u must send a GET message with the name "pg" and the page number, ex:


      

4. Hope it helps u, cause it helped me a lot, and to give an example how i used it goto this site
http://c.1asphost.com/mathclub1/forum.asp?f=001&pg=1


Anything about the code, contact me on either these two emails
firasassaad106@hotmail.com
or
firas488@yahoo.com

and plz post ur result, cause i love to see what happens with u

Best Regards

Firas S Assaad

(in reply to zahid_a)
 
 
Post #: 3
 
 Re: Paging through recordset - 4/5/2005 10:01:24 PM   
  vietnamblood

 

Posts: 14
Score: 0
Joined: 3/28/2005
From:
Status: offline
i think VBS is correct
i think it, too.

(in reply to zahid_a)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Paging through recordset Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts