I have code below to pull out a list of documents from an Access 2000 database - some of which will appear as links to the file (depending on whether a filename is placed in the document field).
The user enters text to a search box - a simple keyword search.
The problem is that when pages are returned, the first page appears ok, but subsequent pages don't.
If for example I enter the string 'st' into the keyword search i get 1-15 of 26 showing correctly and pages [1 2] showing. Yet when i click on page 2 it jumps to the start of a listing of all entries in the database given fields (what you would see if you entered nothing in the keyword search box).
For the keyword search i'm using the 'post' method - 'get' doesn't work.
Very grateful for any thoughts on where i'm going wrong as still can't get it to work after a whole load of google...
CODE
<!--#INCLUDE FILE="adovbs.inc"-->
<% DIM mySQL,objRS
MYsql="SELECT Title, Document " & _
"FROM Policies " & _
"WHERE Title LIKE '%" & Request.form("nameinput") & "%' " & _
"ORDER BY Title asc "
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=path/dbname.mdb"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = 1
objRS.Open mySQL, objConn
DIM intPageRecords, intRecords, intRecordCount, intCurrentPage
DIM intNumberOfPages, intDisplayPage
intPageRecords = Request.Querystring("page")
IF intPageRecords = "" THEN intPageRecords = 1 : intRecords = 1
intRecords = intPageRecords
intPageRecords = ((intPageRecords - 1) * 15) +1
intRecordCount = 0
if objRS.recordcount = 0 then
response.redirect("noresults.asp")
end if
if Not objRS.Eof then
objRS.Move (intPageRecords - 1)
Response.Write ("<hr width='90%' align='left'>")
DO WHILE intRecordCount < 15 and NOT objRS.EOF
if isnull (objRS("Document"))then
Response.write "- " & objRS("Title")
Response.write "<br>"
else
Response.write "- " & " <a href = objRS("Document") & ">" & objRS("Title") & "</a>"
Response.write "<br>"
end if
objRS.movenext
intRecordCount = intRecordCount +1
Loop
END IF
Response.Write ("<hr width='90%' align='left'>")
%>
<%=intPageRecords%> - <%=intPageRecords+(intRecordCount-1)%> of <%=(objRS.RecordCount)%> policies
<p>Policies
<%
intCurrentPage = Request.Querystring("page")
IF intCurrentPage = "" THEN intCurrentPage = 1
intNumberOfPages = int(objRS.RecordCount \ 15)
IF objRS.RecordCount MOD 10<> 0 THEN intNumberOfPages = intNumberOfPages + 1
Response.Write("Pages: [")
FOR intDisplayPage = 1 TO intNumberOfPages
IF Cint(intDisplayPage) = Cint(intCurrentPage) THEN
Response.Write " <b>" & intDisplayPage & "</b> "
ELSE
Response.Write " <a href=""searchresult.asp?page=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "
END IF
NEXT
Response.Write ("]")
Response.write "<br>"
Response.write "<br>"
Response.write "<a href= & "Back to Search Page" & "</a>"
%>
The user enters text to a search box - a simple keyword search.
The problem is that when pages are returned, the first page appears ok, but subsequent pages don't.
If for example I enter the string 'st' into the keyword search i get 1-15 of 26 showing correctly and pages [1 2] showing. Yet when i click on page 2 it jumps to the start of a listing of all entries in the database given fields (what you would see if you entered nothing in the keyword search box).
For the keyword search i'm using the 'post' method - 'get' doesn't work.
Very grateful for any thoughts on where i'm going wrong as still can't get it to work after a whole load of google...
CODE
<!--#INCLUDE FILE="adovbs.inc"-->
<% DIM mySQL,objRS
MYsql="SELECT Title, Document " & _
"FROM Policies " & _
"WHERE Title LIKE '%" & Request.form("nameinput") & "%' " & _
"ORDER BY Title asc "
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=path/dbname.mdb"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = 1
objRS.Open mySQL, objConn
DIM intPageRecords, intRecords, intRecordCount, intCurrentPage
DIM intNumberOfPages, intDisplayPage
intPageRecords = Request.Querystring("page")
IF intPageRecords = "" THEN intPageRecords = 1 : intRecords = 1
intRecords = intPageRecords
intPageRecords = ((intPageRecords - 1) * 15) +1
intRecordCount = 0
if objRS.recordcount = 0 then
response.redirect("noresults.asp")
end if
if Not objRS.Eof then
objRS.Move (intPageRecords - 1)
Response.Write ("<hr width='90%' align='left'>")
DO WHILE intRecordCount < 15 and NOT objRS.EOF
if isnull (objRS("Document"))then
Response.write "- " & objRS("Title")
Response.write "<br>"
else
Response.write "- " & " <a href = objRS("Document") & ">" & objRS("Title") & "</a>"
Response.write "<br>"
end if
objRS.movenext
intRecordCount = intRecordCount +1
Loop
END IF
Response.Write ("<hr width='90%' align='left'>")
%>
<%=intPageRecords%> - <%=intPageRecords+(intRecordCount-1)%> of <%=(objRS.RecordCount)%> policies
<p>Policies
<%
intCurrentPage = Request.Querystring("page")
IF intCurrentPage = "" THEN intCurrentPage = 1
intNumberOfPages = int(objRS.RecordCount \ 15)
IF objRS.RecordCount MOD 10<> 0 THEN intNumberOfPages = intNumberOfPages + 1
Response.Write("Pages: [")
FOR intDisplayPage = 1 TO intNumberOfPages
IF Cint(intDisplayPage) = Cint(intCurrentPage) THEN
Response.Write " <b>" & intDisplayPage & "</b> "
ELSE
Response.Write " <a href=""searchresult.asp?page=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "
END IF
NEXT
Response.Write ("]")
Response.write "<br>"
Response.write "<br>"
Response.write "<a href= & "Back to Search Page" & "</a>"
%>