Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Database search using dropdown list
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

mafifi
Junior Member

USA
308 Posts

Posted - 07 May 2001 :  19:23:45  Show Profile  Send mafifi an ICQ Message
I have written an ASP application that searches a database for telephone numbers. The person will enter the full last name or a partial last name and the script will return all the appropriate records sorted by last name. What I would like to do is to provide the users with a dropdown list that gives the user the choice to search by either last name or first name. The user will choose his search criteria (Last or First names)then will enter either full/partial last name or full/partial first name in a text. The script should bring back the results based on those criteria. Any help on how to get about that will be appreciated. Thanks.

Mo

Doug G
Support Moderator

USA
6493 Posts

Posted - 07 May 2001 :  19:46:33  Show Profile
Assuming you got the choice back in your asp page into a variable I'll call bLastName, do something like

...
...
strSql = "SELECT * FROM table WHERE "
If bLastName = True Then
strSql = strSql & "LastName LIKE '%" & Request.Form("text") & "%'"
Else
strSql = strSql & "FirstName LIKE '%" & Request.Form("text") & "%'"
End If




======
Doug G
======
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 07 May 2001 :  21:29:14  Show Profile  Send mafifi an ICQ Message
Doug G

Here is what I have for my search form
quote:

<FORM ACTION="search.asp" METHOD="get" NAME="SearchForm">
<TABLE BORDER="0" WIDTH="50" CELLPADDING="3">
<TR>
<TD>
<SELECT NAME="TypeSearch">
<OPTION VALUE="LastName">Last Name</OPTION>
<OPTION VALUE="FirstName">First Name</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TDINPUT TYPE="text" SIZE="20" NAME="DaInBox"></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="center" WIDTH="300">
<INPUT TYPE="submit" NAME="B1" VALUE="Search the Directory">
<INPUT TYPE="reset" NAME="B2" VALUE=" Clear "></TD>
</TR>
</TABLE>
</FORM>



and here is the search part and still brings all the records
quote:

<%
Dim SqlJunk

Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
dbGlobalWeb.Open("Employees")
SqlJunk = "SELECT * FROM Employees"

If Request.Form("TypeSearch") = "FirstName" Then
SqlJunk = SqlJunk & " WHERE FirstName LIKE '%" &_
Request.Form("DaInBox") & "%'"
End If

If Request.Form("TypeSearch") = "LastName" Then
SqlJunk = SqlJunk & " WHERE LastName LIKE '%" & _
Request.Form("DaInBox") & "%'"
End If
%>



Thanks for your help

Mo
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 07 May 2001 :  21:59:22  Show Profile  Visit HuwR's Homepage
There is an error on this line

<TDINPUT TYPE="text" SIZE="20" NAME="DaInBox"></TD>

is it the same in your code ?

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 08 May 2001 :  00:08:39  Show Profile
Besides the error HuwR pointed out, you are using the 'get' method on your form, so I don't think Request.Form() is picking anything up. You can insert a response.write Request.Form("DaInBox") to check.


======
Doug G
======
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 08 May 2001 :  19:09:34  Show Profile  Send mafifi an ICQ Message
I changed the method from 'GET' to 'POST' and it worked fine.
Thanks,

Mo
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.96 seconds. Powered By: Snitz Forums 2000 Version 3.4.07