Forum Moderators: open

Message Too Old, No Replies

Paging problem when using parameter based SQL

Paging problem when using parameter based SQL

         

socoolbrewster

2:21 pm on Aug 6, 2003 (gmt 0)

10+ Year Member



I have tried a number of paging scripts and have come to the conclusion it's not the paging script thats the problem. Its gettign crunch time for me as I need the this code is for to go live ASAP

Basically, a user enters a movie title using an input form. The value entered is stored in the variable name: cool

That variable is then passed onto the script using a request form statement in the script. Which is stored in the variable: strSearchtxt

The strSearchtxt is then embedded into an SQL statement and the required records are found.

In running the script it all works fine for the first page but on loading the second page I get: NO PAGE FOUND error

The error lies in the following code:

Response.Write "<a href='fiveon.asp&page="&PageCounter&"&strSearchtxt="&Request("cool") & "'>" & PageCounter & "</a>"

For example:

Say I entered TERMINATOR 3

as the criteria for my search

The first page works fine. On loading the second page the I get a page is not found. On examining the HTTP for the page to see what is getting passed it looks like this:

[localhost...]

As the value is Terminator 3

could it be strSearchtxt=Terminator%203

Causing the problem? what does the 2 stand for?

The full listing for the script is as follows:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>

<%

Dim strSearchtxt
'StrSearchtxt = Server.HTMLEncode(Request.Form("cool"))
strSearchtxt = CStr(Trim(Request("cool"))) ' Get text to define SQL filter search
Dim Con
Dim rsPage
Dim Page
Dim RowCount
Dim PageCounter
Dim strQuote

strQuote = Chr(34) ' The double quote character

'Get the Current page
Page = Request.QueryString("Page")

'If there is no page set it to page 1
If Page = "" then Page = 1

RowCount = 0

set con = server.CreateObject("ADODB.Connection")
Set rsPage = Server.CreateObject("ADODB.Recordset")

lsSQL = "SELECT * FROM review WHERE title = '" & strSearchtxt & "'"

Con.Open "DSN=brewster"

'Need a rich cursor type to support paging
rsPage.CursorType = 3 'adOpenStatic

'Set the number of records in each page to 10
rsPage.PageSize = 5

'Open recordset
rsPage.Open lsSQL, Con

'Set the current page based on the QueryString value
'Must cast it as an integer or else it will have problems.
rsPage.AbsolutePage = cInt(Page)


If Response.IsClientConnected = true then
Response.Write "<TABLE>"

'Loop though each of the records and break out when we
'have reached the max for this page
Do while not rsPage.eof and RowCount < rsPage.PageSize

'Write out content
Response.Write "<tr><td>" & rsPage("title") & "</td></tr>"

rsPage.Movenext
RowCount = RowCount + 1
Loop

Response.Write "</TABLE><p>"


'Page to determine the AbsolutePage to display.
For PageCounter = 1 to rsPage.PageCount
Response.Write "<a href='fiveon.asp&Page="&PageCounter&"&strSearchtxt="&strSearchtxt& "'>" & PageCounter & "</a>"
Next
rsPage.Close
set rsPage = Nothing
End if

%>
</body>
</html>

Sinner_G

4:37 pm on Aug 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 2 is just part of %20, which is the tag that replaces a space.

What happens if you just enter terminator as movie name (or just any other name without space)?

bcolflesh

4:48 pm on Aug 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:

Dim strSearchtxt
'StrSearchtxt = Server.HTMLEncode(Request.Form("cool"))
strSearchtxt = Replace(strSearchtxt, "%20", " ")
strSearchtxt = CStr(Trim(Request("cool"))) ' Get text to define SQL filter search

socoolbrewster

6:00 pm on Aug 6, 2003 (gmt 0)

10+ Year Member



Firstly thanks to everyone above for offering their assistance to my problem. After many hours and days even of changing code and changing code, and with the help of my new best friend from another ASP forum we have cracked it.

Basically the problem with the script was mainly due to the nature of the scripts function. As on passing the variable value from the form to the script on loading the next page(s) the value for the strSearchtxt variable became NULL hence causing the script not to proceed and display an EOF or BOF error. Therefore the script need to call that value from the form again.

Anyway will let the code speak for itself:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>

<%

Dim strSearchtxt

strSearchtxt = Request("cool") ' Get text to define SQL filter search
Dim Con
Dim rsPage
Dim Page
Dim RowCount
Dim PageCounter
Dim strQuote

'Get the Current page
Page = Request.QueryString("Page")

'If there is no page set it to page 1
If Page = "" then Page = 1

RowCount = 0

set con = server.CreateObject("ADODB.Connection")
Set rsPage = Server.CreateObject("ADODB.Recordset")

lsSQL = "SELECT * FROM review WHERE title = '" & strSearchtxt & "'"

Con.Open "brewster"

'Set the number of records in each page to 10
rsPage.PageSize = 5

'Open recordset
rsPage.Open lsSQL, Con,3,3

rsPage.AbsolutePage = cInt(Page)


if not rsPage.eof or rsPage.bof then

Response.Write "<TABLE>"

'Loop though each of the records and break out when we
'have reached the max for this page
Do while not rsPage.eof and RowCount < rsPage.PageSize

'Write out content
Response.Write "<tr><td>" & rsPage("title") & "</td></tr>"

rsPage.Movenext
RowCount = RowCount + 1
Loop

Response.Write "</TABLE><p>"

For PageCounter = 1 to rsPage.PageCount
%>

<a href="fiveon.asp?Page=<%=PageCounter%>&cool=<%=request("cool")%>"><%=PageCounter%></a>
<%
Next
rsPage.Close
set rsPage = Nothing
End if

%>
</body>
</html>