Search within Search Results

Ask a Question related to ASP Database, Design and Development.

  1. #1

    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" (which company
    manufactures them), and I would like to see which of those companies
    would be in "State: PA" then my sql should look like this:
    select * from DB where (State like '%%PA%%') and (Keywords like
    '%%stein%%')

    Instead, for the search within reults I get this:
    select * from DB 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("c_where")
    u_search=request.form("c_search")
    u_prev_search=request.form("c_prev_search")
    u_search_within=request.form("c_search_within")

    if c_search <> "" then
    if c_prev_search = "" then
    c_prev_search=c_search
    else

    c_prev_search=c_prev_search &","& c_search
    g_prev_search=split(c_prev_search,",")
    num_inputted=ubound(g_prev_search)
    end if

    sql= "select * from DB where (" & c_where &" like '%%"& c_search &
    "%%') "

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



    accessdb="DB"
    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">
    <font face="Arial" size="1">
    <a href="<%=rs("Web_Address")%>"
    target="_blank"><%=rs("Supplier")%></a></font></td></table><br>
    <%
    rs.movenext
    loop
    end if
    end if
    %>
    <!-- Begin Form Input Area -->
    <form action="<%= request.servervariables("script_name") %>"
    method="post">
    <select size="1" name="c_where">
    <option value="Keywords" selected>Keywords</option>
    <option value="State">State</option>
    </select>
    <input type="text" name="c_search" value="<%= u_search %>">
    <br>
    <%
    if c_search <> "" then %>
    <input type = "radio" name="c_search_within" checked value="No">
    Search &nbsp;
    <input type = "radio" name="c_search_within" value="Yes"> Search
    within results
    <%
    if c_search_within = "Yes" then %>
    <input type = "hidden" name="c_prev_search" value="<%= c_prev_search
    %>">
    <%
    else %>
    <input type = "hidden" name="c_prev_search" value="<%= c_search %>">
    <% end if %>
    <br>
    <% end if %>
    <input type="submit" value="Search">
    </form>
    <!-- End Form Input Area -->
    <p>&nbsp;</p>
    <%= sql %>
    <br>
    Maria Kovacs Guest

  2. Similar Questions and Discussions

    1. Clikckabel Search Results
      how would i make the URL_of_File cloum clickable? <table width="83%" border="1"> <tr> <td width="32%">File_Name</td> <td...
    2. Search results
      When i search it returns all the rows; not the ones i've searched for. Any help would be appreciated. do i end my search page with CFM also? ...
    3. Sending search results to a results page..with asp
      Please help.. very :confused; Ive setup 4 dynamic drop down boxes which populate themselves from my database, this all works fine..The last box...
    4. search results pages
      How do I separate lengthy search results into 2 or more pages. For example, the first results page lists result 1 - 10 and the next 11 - 20, and so...
    5. Help with search results in asp vbs
      I have this query: SELECT * FROM dbo.subwatch WHERE subname like 'varsubname%' AND vendornum like 'varvendornum%' AND city like 'varcity%' AND...
  3. #2

    Default Re: Search within Search Results

    jus a quick response

    take a look at the variables you're using

    if you're using c_where for the first search i.e
    c_where=Keywords

    make sure that the search within loks something like:
    cwhere=Keywords&c_where2=State

    just so you differentiate between the two fields you're querying... and
    obviously the same goes for their search text(PA and Stein)

    sorry if its in there, but i'm outta time and it would be the obvious answer
    to a problem like that

    laterz


    "Maria Kovacs" <mariakovacs@lycos.com> wrote in message
    news:6f76be22.0310020516.7d44e999@posting.google.c om...
    > 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" (which company
    > manufactures them), and I would like to see which of those companies
    > would be in "State: PA" then my sql should look like this:
    > select * from DB where (State like '%%PA%%') and (Keywords like
    > '%%stein%%')
    >
    > Instead, for the search within reults I get this:
    > select * from DB 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("c_where")
    > u_search=request.form("c_search")
    > u_prev_search=request.form("c_prev_search")
    > u_search_within=request.form("c_search_within")
    >
    > if c_search <> "" then
    > if c_prev_search = "" then
    > c_prev_search=c_search
    > else
    >
    > c_prev_search=c_prev_search &","& c_search
    > g_prev_search=split(c_prev_search,",")
    > num_inputted=ubound(g_prev_search)
    > end if
    >
    > sql= "select * from DB where (" & c_where &" like '%%"& c_search &
    > "%%') "
    >
    > if c_search_within = "Yes" then
    > for counter =0 to num_inputted-1
    > sql=sql& "and (" & c_where & " like '%%"& g_prev_search(counter) &
    > "%%') "
    > next
    > end if
    >
    >
    >
    > accessdb="DB"
    > 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">
    > <font face="Arial" size="1">
    > <a href="<%=rs("Web_Address")%>"
    > target="_blank"><%=rs("Supplier")%></a></font></td></table><br>
    > <%
    > rs.movenext
    > loop
    > end if
    > end if
    > %>
    > <!-- Begin Form Input Area -->
    > <form action="<%= request.servervariables("script_name") %>"
    > method="post">
    > <select size="1" name="c_where">
    > <option value="Keywords" selected>Keywords</option>
    > <option value="State">State</option>
    > </select>
    > <input type="text" name="c_search" value="<%= u_search %>">
    > <br>
    > <%
    > if c_search <> "" then %>
    > <input type = "radio" name="c_search_within" checked value="No">
    > Search &nbsp;
    > <input type = "radio" name="c_search_within" value="Yes"> Search
    > within results
    > <%
    > if c_search_within = "Yes" then %>
    > <input type = "hidden" name="c_prev_search" value="<%= c_prev_search
    > %>">
    > <%
    > else %>
    > <input type = "hidden" name="c_prev_search" value="<%= c_search %>">
    > <% end if %>
    > <br>
    > <% end if %>
    > <input type="submit" value="Search">
    > </form>
    > <!-- End Form Input Area -->
    > <p>&nbsp;</p>
    > <%= sql %>
    > <br>

    Hannibal Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139