472,353 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Problem with paging search results correctly

Hello,
I have set this script up to add paging to a search results page. Which on
the first page works fine. I calculates how many pages there should be
depending on the number of results returned from my search and how many
records I have set it to display per page. All great so far, HOWEVER.....

When you click the next link to see the next 10 results on the next page, it
just dumps the search details and pulls up all the records in the table! So
it finds 320 matching results, and then happily pages through them 10
records at a time, with both the next and prev links working!

I need to find a way of using this paging system in conjunction with the
search results, so if for example I search for "yellow" and I get 18
matching results with the first 10 being displayed on the first page, & I
then click next, I would like to see the last 8 results on the next page,
with the option to click 'prev' and see the previous 10 again. What actually
happens is that it shows me the first 10 matching results and says
displaying page 1 of 2, I click the 'next' link and it suddenly says showing
page 2 of 32 and starts listing all the records from the database starting
at record number 11 !

Please can anyone help me fix this?
Here is my current code:

================================================== =
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/connTS.asp" -->
<%
Dim rsCustSearch__testvar
rsCustSearch__testvar = "%"
If (Request.form("search") <> "") Then
rsCustSearch__testvar = Request.form("search")
End If
%>
<%
Dim rsCustSearch
Dim rsCustSearch_numRows
Const NumPerPage = 10

If Request.QueryString("page") = "" then
CurrentPage = 1 'We're on the first page
Else
CurrentPage = CInt(Request.QueryString("page"))
End If

Set rsCustSearch = Server.CreateObject("ADODB.Recordset")
rsCustSearch.CursorLocation = 3
rsCustSearch.CursorType = 3 'adOpenStatic
rsCustSearch.ActiveConnection = MM_connTS_STRING
rsCustSearch.Source = "SELECT ProductID, ProductName, Keywords, ProductPict
FROM Products WHERE Keywords LIKE '%" + Replace(rsCustSearch__testvar, "'",
"''") + "%' OR ProductName LIKE '%" + Replace(rsCustSearch__testvar, "'",
"''") + "%'"

rsCustSearch.LockType = 1
rsCustSearch.Open()

If Not rsCustSearch.EOF Then
rsCustSearch.MoveFirst
rsCustSearch.PageSize = NumPerPage
TotalPages = rsCustSearch.PageCount
maxrecs = rsCustSearch.Pagesize

'Set the absolute (current) page
rsCustSearch.AbsolutePage = CurrentPage
End If

Dim Count
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsCustSearch_numRows = rsCustSearch_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats
variables

Dim rsCustSearch_total
'Dim rsCustSearch_first
'Dim rsCustSearch_last

' set the record count
rsCustSearch_total = rsCustSearch.RecordCount

' set the number of rows displayed on this page
'If (rsCustSearch_numRows < 0) Then
' rsCustSearch_numRows = rsCustSearch_total
'Elseif (rsCustSearch_numRows = 0) Then
' rsCustSearch_numRows = 1
'End If

' set the first and last displayed record
'rsCustSearch_first = 1
'rsCustSearch_last = rsCustSearch_first + rsCustSearch_numRows - 1

' if we have the correct record count, check the other stats
'If (rsCustSearch_total <> -1) Then
' If (rsCustSearch_first > rsCustSearch_total) Then
' rsCustSearch_first = rsCustSearch_total
' End If
'If (rsCustSearch_last > rsCustSearch_total) Then
' rsCustSearch_last = rsCustSearch_total
' End If
'If (rsCustSearch_numRows > rsCustSearch_total) Then
' rsCustSearch_numRows = rsCustSearch_total
'End If
'End If
%>

<%
' *** Recordset Stats: if we don't know the record count, manually count
them

If (rsCustSearch_total = -1) Then

' count the total records by iterating through the recordset
rsCustSearch_total=0
While (Not rsCustSearch.EOF)
rsCustSearch_total = rsCustSearch_total + 1
rsCustSearch.MoveNext
Wend

' reset the cursor to the beginning
'If (rsCustSearch.CursorType > 0) Then
' rsCustSearch.MoveFirst
'Else
' rsCustSearch.Requery
'End If

' set the number of rows displayed on this page
If (rsCustSearch_numRows < 0 Or rsCustSearch_numRows > rsCustSearch_total)
Then
rsCustSearch_numRows = rsCustSearch_total
End If

' set the first and last displayed record
rsCustSearch_first = 1
rsCustSearch_last = rsCustSearch_first + rsCustSearch_numRows - 1

If (rsCustSearch_first > rsCustSearch_total) Then
rsCustSearch_first = rsCustSearch_total
End If
If (rsCustSearch_last > rsCustSearch_total) Then
rsCustSearch_last = rsCustSearch_total
End If

End If
%>
<%
Dim MM_paramName
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL
and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem &
Server.URLencode(Request.QueryString(MM_item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem &
Server.URLencode(Request.Form(MM_item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the
strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<html><!-- InstanceBegin template="/Templates/home.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Search Results</title>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0">
<form action="SearchResults.asp" method="post" name="frmsearch"
id="frmsearch">

<input name="search" type="text" class="formelement"
id="search">
<input name="Submit" type="submit" class="formelement"
value="Submit">form><div align="left"><!-- InstanceBeginEditable
name="body" -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><div align="center"><img src="images/search.jpg"><br>
<font face="Arial, Helvetica, sans-serif"><strong>Your
Search </strong><font size="3">returned <%=(rsCustSearch_total)%>
results</font></font></div>
<font size="2" face="Verdana">Displaying page <%=CurrentPage%>
of <%=TotalPages%>:</font></b> &nbsp;
<%
'Display PREV page link, if appropriate
If Not CurrentPage = 1 Then
Response.Write "<a href='" & ScriptName & "?page=" & CurrentPage - 1 &
"'>Prev</a> | "
Else
Response.Write "Prev | "
End If

'Display NEXT page link, if appropriate
If Not CurrentPage = TotalPages Then
Response.Write "<a href='" & ScriptName & "?page=" & CurrentPage + 1 &
"'>Next</a>"
Else
Response.Write "Next"
End If
%></td>
</tr>
<%
'Loop to display data on current page.
Do While Not rsCustSearch.EOF and Count < rsCustSearch.PageSize OR
howmanyrecs>=maxrecs
%>
<tr>
<td width="49%"><div
align="right"><b><%=(rsCustSearch.Fields.Item("Pro ductName").Value)%><br><A
href="ProductDetails.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) &
"ProductID=" & rsCustSearch.Fields.Item("ProductID").Value %>">View Item
Details</a></div></td>
<td width="51%"><A href="ProductDetails.asp?<%= MM_keepURL &
MM_joinChar(MM_keepURL) & "ProductID=" &
rsCustSearch.Fields.Item("ProductID").Value %>"><img
src="http://www.bathchain.co.uk/images/<%=(rsCustSearch.Fields.Item("Product
Pict").Value)%>" border="0" width="100" height="100"></A></td>
</tr>
<%

rsCustSearch.MoveNext
Count = Count + 1
Loop
%>
</table>
<!-- InstanceEndEditable --><br>
</div>
</body>
<!-- InstanceEnd --></html>
<%
rsCustSearch.Close()
Set rsCustSearch = Nothing
%>
================================================== =

It is basicly losing the search recordset details when I click 'next' or
'prev' & I need someone to show me how to get round this!

THANKYOU in advance for your help.......
Joseph
CharitiesOnline
Jul 19 '05 #1
2 3350
"CharitiesOnline" <ch*************@hotmail.com> wrote in message
news:Ia**************@news-binary.blueyonder.co.uk...
Hello,
I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be
depending on the number of results returned from my search and how many records I have set it to display per page. All great so far, HOWEVER.....
When you click the next link to see the next 10 results on the next page, it just dumps the search details and pulls up all the records in the table! So it finds 320 matching results, and then happily pages through them 10
records at a time, with both the next and prev links working!

I need to find a way of using this paging system in conjunction with the search results, so if for example I search for "yellow" and I get 18
matching results with the first 10 being displayed on the first page, & I then click next, I would like to see the last 8 results on the next page, with the option to click 'prev' and see the previous 10 again. What actually happens is that it shows me the first 10 matching results and says
displaying page 1 of 2, I click the 'next' link and it suddenly says showing page 2 of 32 and starts listing all the records from the database starting at record number 11 !

Please can anyone help me fix this?


Please don't multi-post

Newsgroup Etiquette:
aspfaq.com/2081
Recordset Paging:
aspfaq.com/2120

HTH
-Chris Hohmann
Jul 19 '05 #2
And now for an answer to your actual question... :)

The problem is that the search criteria is not being passed along when
you page through the recordset. You're code is looking for
Reuqest.Form("seach"). Therefore you must either

1. Replace your previous/next links with a form that passes the search
criteria.

OR

2. Include the search criteria in the links and modify your code to
check for both Request.Form("search") and Request.Querystring("search")
HTH
-Chris


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg...
0
by: aftab | last post by:
Hi As i am doing a search results page where we have to list lots of results using paging in ASP.NET. I have two different databases one from...
2
by: Calvin KD | last post by:
Hi everyone, I have a datagrid to display search results. The search results at this stage we only return the first 500 records to speed up the...
2
by: Arsalan Ahmad | last post by:
Hi, May be I am a newbie, or may be i dont have that much insight in following systems ..i.e. why i have some confusions as below: In many...
0
by: lewis | last post by:
I have a simple web site that does a search in a table. On the top of the screen i have several fields that allow a user to type in data and a...
18
by: daveeboi | last post by:
When running the script below I am able to get all related table results and display them the way I want. When it came to my paging script I entered...
0
by: jimmmeh | last post by:
Hey guys, I will try and keep this as concise as I can. Basically I am developing a site which uses a Wizard Control (dynamically generated from a...
1
by: russot00 | last post by:
I have 3 drop down menus that are used in a search to locate restaurants in a db. All of the drop down menus function, a search can be submitted with...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.