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.

<title>CodeAve.com(Search Within Search Results)</title>
<body bgcolor="#FFFFFF"><%
u_search=request.form("u_search")
u_prev_search=request.form("u_prev_search")
u_search_within=request.form("u_search_within")
' 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
u_prev_search=u_search
else
'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
g_prev_search=split(u_prev_search,",")
num_inputted=ubound(g_prev_search)
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) & "%%') "
next
end if ' end the search within a search
accessdb="state_info"
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
else
rs.movefirst
do while Not rs.eof
%>
<%= rs("capital") %><br><%
rs.movenext
loop
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
%>">
<br><%'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 %>
<br><% end if ' end check of of first search %>
<input type="submit" value="Search">
</form>
<!-- End Form Input Area -->
<p>&nbsp;</p><%= sql %>