建站代码网

热门标签

在搜索结果中搜索

想添加值到你的当前搜索里面吗?允许你的用户从搜索结果中搜索。正如数据库是有必要为用户连续地搜索他们真的想要的内容。下面的例子会利用到我们在美国首都的数据库。首先的两个单选按钮会表明搜索(默认)或者当前结果的搜索功能。从当前功能中搜索会用到第一个搜索功能,并且能把它添加到新搜索功能等等。注意数据库只有50个规则。在信息上搜索为了最好的结果和从那些结果中搜索其他的信息。

<title>Www.ttasp.net(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")
检查看用户是否输入调查的内容
if u_search <> "" then
如果用户输入搜索和最初的搜索功能
和当前搜索等同的prev_搜索
if u_prev_search = "" then 
u_prev_search=u_search
else
如果用户输入了搜索预先功能,然后添加到prev_搜索

u_prev_search=u_prev_search &","& u_search 如果有预先的搜索功能,那把u_ 搜索分开成列 g_prev_search=split(u_prev_search,",") num_inputted=ubound(g_prev_search) end if sql= "select * from states where (capital like '%%"& u_search & "%%') "
检查看用户是否要求通过给新搜索的sql附加预先搜索功能来得到预先搜索的结果

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 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 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 %>