Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pagination: second and subsequent pages don't appear 1

Status
Not open for further replies.

evillin

Technical User
Jan 2, 2004
20
GB
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>"

%>
 
you need to pass your search string along with the page number, so that it can requery, and page to the right area.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Thanks very much for this - sorry - can you please show me how to do this - everything i have tried hasn't worked?

 

Response.Write " <a href=""searchresult.asp?nameinput=" & Request.form("nameinput") & "&page=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Thanks Drex for taking the time to help - tried this but still have problem.

Doesn't throw up an error when make change you suggested and appears ok when i hover over link to page 2 for results of entering 'st' but when i click on page 2 it takes me to page 2 of results i would get if i entered nothing - i.e page two of all entries in database instead of page 2 for 'st'.

There are 6 lines that should appear on page 2 (21-26) of 26. Instead i see 21-40 of 157!!!

Am confused - grateful for any help...
 
oops my bad, change the Request.form("nameinput") in the correction above to Request.querystring("nameinput")

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Drex - you're a star - it works - many many thanks - was ripping my hair out :)

The key to this was changing the form from 'post' to 'get' and 'request.form' to 'request.querystring' throughout script.

Happy Christmas and best wishes for 2005 to all...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top