[thelist] Help! ASP Search Script

Giles Carey | Element Design giles at elementdesign.fsnet.co.uk
Fri Dec 27 09:34:37 CST 2002


Hi there!
I've set up an ASP Database search script which searches for keywords the
user unputs in different columns of the table. However, even when there are
multiple records found matching thekeywords searched for, only one result is
ever paged. Help me as i wish to display all the results, not just the first
one found in the database!
Here is the code:

<html>
<title>CodeAve.com(Search db by Field)</title>
<%
u_input = trim(request.form("u_input")) 'u_input is the varible for user
input

u_field=request.form("u_field") 'the dropdown varible for user inputted
search field

if u_input <> "" then ' If the user entered a value query the db
accessdb="database/DUpaypal" ' name of the access db
table_name="PRODUCTS"   ' name of the table within the access db
cn="driver={microsoft access driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
sql = "select * from "& table_name &" where " & u_field & " like  '%%" &
u_input & "%%' "
rs.Open sql, cn
howmanyrecs=rs.recordcount+2
if rs.eof or rs.bof then
response.write "<table width=100% border=0><tr bgcolor=#3366cc
background=bluebg.gif><td bgcolor=#3366cc background=bluebg.gif><div
align=right><font face=verdana color=white size=2><b>" &u_input&
"</td></tr><tr><td><font face=verdana size=2 color=black>No results found
for&nbsp;<b>"  &u_input& "</b>. Please try searching our database
again.</td></tr></table>"
observations=0
else
observations=1
end if                'end check for observations
end if                'end check for user input
%>
<% 'If there are observations then display them
if observations > 0 then %>
<table width=100% border=0><tr bgcolor=#3366cc background=bluebg.gif><td
bgcolor=#3366cc background=bluebg.gif><div align=right><font face=verdana
color=white size=2>
<% response.write "Search results for <b>" &u_input& "</b>"
%></td></tr><tr><td><font face=verdana size=2 color=black><% response.write
howmanyrecs %> entries found.


<table border="0" cellspacing="2" cellpadding="2">
                <tr align="left" valign="middle">
                  <td align="center" valign="top"><img
src="images/<%=(rs.Fields.Item("PRO_IMAGE").Value)%>" border="0" vspace="0"
hspace="0" alt="<%=(rs.Fields.Item("PRO_NAME").Value)%>" height=150></td>
                  <td valign="top">
                    <table width="100%" border="0" cellspacing="2"
cellpadding="2">
                      <tr>
                        <td align="left" valign="middle" colspan="2"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Title:</b> <font
color=#3366cc

<b><%=(rs.Fields.Item("PRO_NAME").Value)%></b><b>&nbsp;<font face=verdana
size=2 color=black>(Size:<font
color=#3366cc><%=(rs.Fields.Item("PRO_SHIP").Value)%><font
color=black>)</b></font></td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2" color=black><b>Date
Added:</b> <font color=3366cc>

<%=(rs.Fields.Item("PRO_DATED").Value)%></font></td>
                        <td align="left" valign="middle"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><font
color=black>Artist:</b>
                         <font
color=#3366cc><%=(rs.Fields.Item("PRO_BRAND").Value)%></font></td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Price
Delivered:</b>
                          <font
color="#FF0000"><b>£<%=(rs.Fields.Item("PRO_PRICE").Value)%></b></font>
</font></td>
                        <td align="left" valign="middle"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Shipping
                          Information:</b>
<%=(rs.Fields.Item("PRO_INFO").Value)%></font></td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" colspan="2"><font
face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Description:</b>
                          <% =(rs.Fields.Item("PRO_DESCRIPTION").Value)%>
                          </font></td>
                      </tr>
                      <tr align="right">
                        <td valign="middle" colspan="2">

<a href="#"
onclick="window.open('https://www.paypal.com/cart/add=1&business=mail%40artw
orthy.co.uk&item_name=<%=(rs.Fields.Item("PRO_NAME").Value)%>&item_number=<%
=(rs.Fields.Item("PRO_ID").Value)%>&amount=<%=(rs.Fields.Item("PRO_PRICE").V
alue)%>&currency_code=GBP&return=<%= myReturnURL %>&cancel_return=<%=
myCancelURL
%>','cartwin','width=600,height=400,scrollbars,location,resizable,status');"
>
<img src="add.gif" border="0"></a>



                        </td>
                      </tr>
                    </table>




</td></tr>
<%
rs.MoveFirst
Do Until rs.EOF
rs.MoveNext
Loop

%>
</table>
<tr>

</tr>
</table>
<% end if 'end of check of obs for display %>
</body></html>

I cannot understand why this doesn't work!

Please help,

TIA,

Giles
giles at elementdesign.biz




More information about the thelist mailing list