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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing search values from one page to next 1

Status
Not open for further replies.

laker67

Programmer
Jan 18, 2004
31
0
0
US
Hi,
I was wondering if there is a way to save the values selected by the user from a search form . By default i get the first page results from the database . When the user clicks the Next page ,i get from the database the results for the 2nd page and so on. I'm wondering what would be the best way to keep track of all these values selected by the user so that i can send to the database with the same values and all that changes would be the page number .
Thanks!!!!!!!!
 
I can think of two methods of the top of my head;
1) Session Variables/Cookies
When you first load your results page you could check to see if there is a page number in the querystring. If there isn't one than you can put the values for the search fields into session variables. After doing tat check you can then build your SQL statement and, using recordset paging, display the correct page (page 1 if not set in querystring). Your forward/back/pagenumbers buttons could be displayed based on the number of pages that the recordset would supply and then you just place a variable in the querystring to hold the target page number.
Code:
[b]Results.asp - Session Example[/b]
<%
Option Explicit

Dim pageno
'If the page number isn't set, we need to set the session variables becaus this is first visit to results from search
If Request.QueryString("pageno") = "" Then
   Session("search_field_1") = Request.Form("search_field_1")
   Session("search_field_2") = Request.Form("search_field_2")
   Session("search_field_3") = Request.Form("search_field_3")
   pageno = 1
Else
   pageno = cInt(Request.QueryString("pageno"))
End If

'Now do your ADO stuff here, making the SQL statement using the Session variables
'Using paging, display your results, etc

'Now build links to other pages based on number of pages available from recordset
'   I will give the previous and next links as examples
'   assume the variable MaxPages was set in the ADO section above
If pageno = 1 Then
   Response.Write "Previous"
Else
   Response.Write "<a href=""Results.asp?pageno=" & (pageno - 1) & """>Previous</a>"
End If

If pageno = MaxPages Then
   response.Write "Next"
Else
   Response.Write "<a href=""Results.asp?pageno=" & (pageno+1) & """>Next</a>"
End If

2) QueryString
Each time you load your results page, take the search values from the querystring. Build the beginning of a new querystring and then append that to each forward/back/page number link you create later on so that when they click on the link the values are passed to the next page.
Code:
[b]Results.asp - QueryString Example[/b]
<%
Option Explicit

'if the page number is not set, get the values from Request.Form (page 1), otherwise get them from Request.QueryString

Dim search_field_1, search_field_2
Dim search_qry
If Request.QueryString("pageno") = "" Then
   search_field_1 = Request.Form("search_field_1")
   search_field_2 = Request.Form("search_field_2")
   pageno = 1
Else
   search_field_1 = Request.QueryString("search_field_1")
   search_field_2 = Request.QueryString("search_field_2")
   pageno = cInt(Request.QueryString("pageno"))
End If

'build the parial querystring for later results links
search_qry = "search_field_1=" & search_field_1 & "&search_field_2=" & search_field_2

'all your ADO and display stuff, fun fun

'forward and back links, like last example
If pageno = 1 Then
   Response.Write "Previous"
Else
   'use the partial query string to add the search values in
   Response.Write "<a href=""Results.asp?" & search_qry & "&pageno=" & (pageno - 1) & """>Previous</a>"
End If

If pageno = MaxPages Then
   response.Write "Next"
Else
   'use the partial querystring to add the search values in
   Response.Write "<a href=""Results.asp?" & search_qry & "&pageno=" & (pageno+1) & """>Next</a>"
End If
%>

Hope that was what you were looking for,
-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Those are the 2 methods i had in mind and i appreciate that you explained in detail .Thanks alot .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top