473,837 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="VB SCRIPT" CODEPAGE="1252" %>
<!--#include file="Connectio ns/connTS.asp" -->
<%
Dim rsCustSearch__t estvar
rsCustSearch__t estvar = "%"
If (Request.form(" search") <> "") Then
rsCustSearch__t estvar = Request.form("s earch")
End If
%>
<%
Dim rsCustSearch
Dim rsCustSearch_nu mRows
Const NumPerPage = 10

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

Set rsCustSearch = Server.CreateOb ject("ADODB.Rec ordset")
rsCustSearch.Cu rsorLocation = 3
rsCustSearch.Cu rsorType = 3 'adOpenStatic
rsCustSearch.Ac tiveConnection = MM_connTS_STRIN G
rsCustSearch.So urce = "SELECT ProductID, ProductName, Keywords, ProductPict
FROM Products WHERE Keywords LIKE '%" + Replace(rsCustS earch__testvar, "'",
"''") + "%' OR ProductName LIKE '%" + Replace(rsCustS earch__testvar, "'",
"''") + "%'"

rsCustSearch.Lo ckType = 1
rsCustSearch.Op en()

If Not rsCustSearch.EO F Then
rsCustSearch.Mo veFirst
rsCustSearch.Pa geSize = NumPerPage
TotalPages = rsCustSearch.Pa geCount
maxrecs = rsCustSearch.Pa gesize

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

Dim Count
%>
<%
Dim Repeat1__numRow s
Dim Repeat1__index

Repeat1__numRow s = -1
Repeat1__index = 0
rsCustSearch_nu mRows = rsCustSearch_nu mRows + Repeat1__numRow s
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats
variables

Dim rsCustSearch_to tal
'Dim rsCustSearch_fi rst
'Dim rsCustSearch_la st

' set the record count
rsCustSearch_to tal = rsCustSearch.Re cordCount

' set the number of rows displayed on this page
'If (rsCustSearch_n umRows < 0) Then
' rsCustSearch_nu mRows = rsCustSearch_to tal
'Elseif (rsCustSearch_n umRows = 0) Then
' rsCustSearch_nu mRows = 1
'End If

' set the first and last displayed record
'rsCustSearch_f irst = 1
'rsCustSearch_l ast = rsCustSearch_fi rst + rsCustSearch_nu mRows - 1

' if we have the correct record count, check the other stats
'If (rsCustSearch_t otal <> -1) Then
' If (rsCustSearch_f irst > rsCustSearch_to tal) Then
' rsCustSearch_fi rst = rsCustSearch_to tal
' End If
'If (rsCustSearch_l ast > rsCustSearch_to tal) Then
' rsCustSearch_la st = rsCustSearch_to tal
' End If
'If (rsCustSearch_n umRows > rsCustSearch_to tal) Then
' rsCustSearch_nu mRows = rsCustSearch_to tal
'End If
'End If
%>

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

If (rsCustSearch_t otal = -1) Then

' count the total records by iterating through the recordset
rsCustSearch_to tal=0
While (Not rsCustSearch.EO F)
rsCustSearch_to tal = rsCustSearch_to tal + 1
rsCustSearch.Mo veNext
Wend

' reset the cursor to the beginning
'If (rsCustSearch.C ursorType > 0) Then
' rsCustSearch.Mo veFirst
'Else
' rsCustSearch.Re query
'End If

' set the number of rows displayed on this page
If (rsCustSearch_n umRows < 0 Or rsCustSearch_nu mRows > rsCustSearch_to tal)
Then
rsCustSearch_nu mRows = rsCustSearch_to tal
End If

' set the first and last displayed record
rsCustSearch_fi rst = 1
rsCustSearch_la st = rsCustSearch_fi rst + rsCustSearch_nu mRows - 1

If (rsCustSearch_f irst > rsCustSearch_to tal) Then
rsCustSearch_fi rst = rsCustSearch_to tal
End If
If (rsCustSearch_l ast > rsCustSearch_to tal) Then
rsCustSearch_la st = rsCustSearch_to tal
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.QuerySt ring
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_rem oveList,MM_next Item,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem &
Server.URLencod e(Request.Query String(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_rem oveList,MM_next Item,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem &
Server.URLencod e(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_keepBo th, Len(MM_keepBoth ) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepUR L, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepFo rm, Len(MM_keepForm ) - 1)
End If

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

<body bgcolor="#FFFFF F" text="#000000" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0 ">
<form action="SearchR esults.asp" method="post" name="frmsearch "
id="frmsearch" >

<input name="search" type="text" class="formelem ent"
id="search">
<input name="Submit" type="submit" class="formelem ent"
value="Submit"> form><div align="left"><!-- InstanceBeginEd itable
name="body" -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td colspan="2"><di v align="center"> <img src="images/search.jpg"><br >
<font face="Arial, Helvetica, sans-serif"><strong> Your
Search </strong><font size="3">return ed <%=(rsCustSearc h_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.EO F and Count < rsCustSearch.Pa geSize OR
howmanyrecs>=ma xrecs
%>
<tr>
<td width="49%"><di v
align="right">< b><%=(rsCustSea rch.Fields.Item ("ProductName") .Value)%><br><A
href="ProductDe tails.asp?<%= MM_keepURL & MM_joinChar(MM_ keepURL) &
"ProductID= " & rsCustSearch.Fi elds.Item("Prod uctID").Value %>">View Item
Details</a></div></td>
<td width="51%"><A href="ProductDe tails.asp?<%= MM_keepURL &
MM_joinChar(MM_ keepURL) & "ProductID= " &
rsCustSearch.Fi elds.Item("Prod uctID").Value %>"><img
src="http://www.bathchain.c o.uk/images/<%=(rsCustSearc h.Fields.Item(" Product
Pict").Value)%> " border="0" width="100" height="100"></A></td>
</tr>
<%

rsCustSearch.Mo veNext
Count = Count + 1
Loop
%>
</table>
<!-- InstanceEndEdit able --><br>
</div>
</body>
<!-- InstanceEnd --></html>
<%
rsCustSearch.Cl ose()
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 3539
"CharitiesOnlin e" <ch************ *@hotmail.com> wrote in message
news:Ia******** ******@news-binary.blueyond er.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("s each"). 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("s earch") and Request.Queryst ring("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
2265
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 it shows 5 pages. (I am showing page numbers at the bottom of the dg.) When I click on the pages nothing happens until I get to the last page. Then and only then is the last page displayed. If I go back through the pages the second to last page displayes the first page again.
0
1108
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 sqlserver and one from oracle. so i have to query the tables in Sqlserver and oracle and fetch the results. say for example i have fields hotelID and hotelName in sqlserver
2
3091
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 search. The problem is, if I turn the EnableViewState on, the search regularly failed with a message that says tempdb is full... It does not however happens all the time. I have tried to turn the EnableViewState off, that seems to do the trick but causes another problem, the datagrid's paging does...
2
2634
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 websites, when search is performed on some keywords (not only including google which perform general search but other sites which perform seach on a particular type of item in their database) then many search results are obtained (for example more than 100 or even more than 1000) but only limited...
0
661
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 search button. In the click of the button i set the FilterExpression of the datasource. (I am doing this manually because the where clause can be complex) So it may look like something as simple as ds.FilterExpression = "name like 'abc%'";
18
2050
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 and limited the rows per page to 2 (for a 3 record result) I get the first 2 records on page fine, when click through to next I get notices about undefined variables. I really dont understand. The code is, <html> <head> </head> <body> <?php
0
916
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 database) as a search form linked to a results page which takes out all the information from the wizard and searches the database for matching items. I cannot make use of javascript, sessions OR cookies and so I am totally reliant on viewstate for the whole operation. For this reason my wizard...
1
1631
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 any combination of drop downs and the results are sorted by restaurant name. The problem occurs when you do not select anything from a drop down ("All" is submitted for all drop downs) and submit the search, the following error occurs: "Can't connect because You have an error in your SQL syntax;...
1
1963
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 in the database versus to creating a CLR sort expression and allowing the GridView to perform the sorting and paging. How do people feel about each option for (1) simple sorts (alphabetical, compound alphabetical)
0
9842
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10874
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10566
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10623
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.