- ASP - Database Table Display
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Search Within Search Results
Want to add value to your current search?  Allow your users to search from within search results.  As databases grow the necessity for the user to continually narrow a search to the item that they truly want will grow also.  The following example utilizes our db on U.S. State capitals.  Upon the first search two radio buttons will appear indicating a search (default) or a search within the current results.  Searching within the current results will take the first search and add it to the new search and so on.  Note the db only has 50 observations in it.  For best results search on a letter and search for another letter within those results.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<title> Within Search Results)</title>
<body bgcolor="#FFFFFF">
' check to see if the user has inputted anything to search
if u_search <> "" then
'if the user inputted a search and it is the first search
'make prev_search equal to the current search 
if u_prev_search = "" then 
'if the user entered a search prior add it to the prev_search
u_prev_search=u_prev_search &","& u_search
'if there are previous searches split up the u_search field into arrays
end if
sql= "select * from states where (capital like '%%"& u_search & "%%') "
'Checks to see if the user requested to search within the results of a
'previous search by appending the previous search to the sql
'of the new search
if u_search_within = "Yes" then
for counter =0 to num_inputted-1
sql=sql& "and (capital like '%%"& g_prev_search(counter) & "%%') "
end if ' end the search within a search
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, cn
' if there are no records found display no records found
if rs.eof then

No records were found 
<%' if records are found display them
do while Not rs.eof
<%= rs("capital") %>
end if ' end of check for records 
end if ' end the check for a user inputted value

<!-- Begin Form Input Area -->
<form action="<%= request.servervariables("script_name") %>" method="post">
<input type="text" name="u_search" value="<%= u_search %>">
<%'Checks to see if the user has submitted a search request
'if so then display the option to search or search within results
if u_search <> "" then %>

<input type = "radio" name="u_search_within" checked value="No"> Search &nbsp; 
<input type = "radio" name="u_search_within" value="Yes"> Search within results 
<%' if the user indicates a search within results then add the surrent search to all previous
if u_search_within = "Yes" then %>

<input type = "hidden" name="u_prev_search" value="<%= u_prev_search %>">
<%'if the user is not searching within results make the prev_search eqaul to u_search 
else %>

<input type = "hidden" name="u_prev_search" value="<%= u_search %>">
<% end if ' end check of search within a search %>
<% end if ' end check of of first search %>
<input type="submit" value="Search">
<!-- End Form Input Area -->
<%= sql %>




ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2019
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3