Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2003, 12:06 PM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search within search results

I am trying to do a search within query results:

My first search executes fine, but my second search uses the WHERE parameters of my first search.

For Instance if my first search was "Keyword: stein", and I would like to see which of those companies would be in "State: PA" then my sql should look like this:
select * from VIPP where (State like '%%PA%%') and (Keywords like '%%stein%%')

Instead I get this:
select * from VIPP where (State like '%%PA%%') and (State like '%%stein%%')

What am I missing?

Here is my code:
<title>Search within Results</title>
<%
u_where=request.form("u_where")
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
if u_prev_search = "" then
u_prev_search=u_search
else

u_prev_search=u_prev_search &","& u_search
g_prev_search=split(u_prev_search,",")
num_inputted=ubound(g_prev_search)
end if

sql= "select * from VIPP where (" & u_where &" like '%%"& u_search & "%%') "

if u_search_within = "Yes" then
for counter =0 to num_inputted-1
sql=sql& "and (" & u_where & " like '%%"& g_prev_search(counter) & "%%') "
next
end if



accessdb="VIPP"
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
<%
else
rs.movefirst
do while Not rs.eof
%>
     <table> <td width="200" valign="top" align="left">

    <a href="<%=rs("Web_Address")%>" target="_blank"><%=rs("Supplier")%></a></td></table><br>
<%
rs.movenext
loop
end if
end if
%>

<form action="<%= request.servervariables("script_name") %>" method="post">
<select size="1" name="u_where">
                 <option value="Keywords" selected>Keywords</option>
                <option value="State">State</option>
             </select>
<input type="text" name="u_search" value="<%= u_search %>">
<br>
<%
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 u_search_within = "Yes" then %>
<input type = "hidden" name="u_prev_search" value="<%= u_prev_search %>">
<%
else %>
<input type = "hidden" name="u_prev_search" value="<%= u_search %>">
<% end if %>
<br>
<% end if %>
<input type="submit" value="Search">
</form>

<p>&nbsp;</p>
<%= sql %>
<br>
 
Old November 18th, 2003, 07:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The SQL you are adding on for the previous search where value is using u_where. Should it be using u_search_within instead?

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter double search results ABplace Beginning VB 6 3 June 28th, 2007 08:11 AM
How do I display search results... aspiretech9 PHP How-To 1 April 26th, 2005 10:12 AM
How do I display search results... aspiretech9 Beginning PHP 1 April 25th, 2005 04:59 PM
How do I display search results... aspiretech9 PHP Databases 1 April 25th, 2005 12:11 PM
Customize Search Results bmains ASP.NET 1.0 and 1.1 Professional 4 January 15th, 2004 08:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.