Advanced search form

This is a discussion on "Advanced search form" within the Classic ASP section. This forum, and the thread "Advanced search form are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Mar 4th, 2005, 11:11
New Member
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Advanced search form

Hi there,

I have an advanced search form below which works fine except for the last sqlstring which needs to be linked to the other criteria.

<%
dim objconn
dim strconnect
dim objrs
dim sqlstring

set objconn = Server.CreateObject("ADODB.Connection")
strconnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & Server.MapPath("whos_who.mdb")

objconn.open strconnect
Set objrs = Server.CreateObject("ADODB.RecordSet")

sqlstring = " SELECT Personnel.*, specialists.spu_id " & _
" FROM Personnel, specialists "

If Request.form("name") <> "" Then
sqlstring = sqlstring & " AND first_name LIKE '%" & Request.form("name") & "%'"
End If
If Request.form("surname") <> "" Then
sqlstring = sqlstring & " AND surname LIKE '" & Request.form("surname") & "'"
End If
If Request.form("ext") <> "" Then
sqlstring = sqlstring & " AND extension_id LIKE '" & Request.form("ext") & "'"
End If
If Request.form("initials") <> "" Then
sqlstring = sqlstring & " AND initials LIKE '%" & Request.form("initials") & "%'"
End If
If Request.form("mob") <> "" Then
sqlstring = sqlstring & " AND mobile_no LIKE '%" & Request.form("mob") & "%'"
End If
If Request.form("tel") <> "" Then
sqlstring = sqlstring & " AND ddl_no LIKE '%" & Request.form("tel") & "%'"
End If
If Request.form("fax") <> "" Then
sqlstring = sqlstring & " AND fax_ddl LIKE '%" & Request.form("fax") & "%'"
End If
If Request.form("email") <> "" Then
sqlstring = sqlstring & " AND email LIKE '%" & Request.form("email") & "%'"
End If
If Request.form("tk") <> "" Then
sqlstring = sqlstring & " AND timekeep_id LIKE '%" & Request.form("tk") & "%'"
End If
If Request.form("office") <> "" Then
sqlstring = sqlstring & " AND office = " & Request.form("office")
End If
If Request.form("division") <> "" Then
sqlstring = sqlstring & " AND division = " & Request.form("division")
End If
If Request.form("department") <> "" Then
sqlstring = sqlstring & " AND dept_id = " & Request.form("department")
End If
If Request.form("team") <> "" Then
sqlstring = sqlstring & " AND team = " & Request.form("team")
End if
If Request.form("spec") <> "" Then
sqlstring = " SELECT Personnel.*, specialists.spu_id " & _
" FROM Personnel, specialists " & _
" WHERE Personnel.p_id = specialists.p_id " & _
" AND specialists.spu_id = " & CInt(request.form("spec"))
End If
response.write request.form("spec")
objrs.open sqlstring, objconn, 3, 3

%>

Could anyone give me some advice on how to do this?

thanx in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Mar 4th, 2005, 20:57
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
First the "SELECT __ FROM table, table" format isn't a clear or reliable way of getting information from 2 tables together. You're better of doing a LEFT JOIN, INNER JOIN, or RIGHT JOIN as you're explicitly telling the db what to do if there isn't matching information in either table.

That mostly applies to the initial part
Code: Select all
sqlstring = " SELECT Personnel.*, specialists.spu_id " & _ 
" FROM Personnel, specialists "
not knowing enough about how your db is setup I could only guess that a LEFT JOIN would be the best one, so
Code: Select all
sqlstring = " SELECT Personnel.*, specialists.spu_id " & _ 
" FROM Personnel LEFT JOIN specialists ON Personnel.p_id=specialists.spu_id WHERE p_id<>'' "
This will return a recordset with everything in Personnel along with the Specialists.spu_id when there's one that matches (otherwise a NULL).

Then you can filter that with your WHERE statements; notice I added the WHERE to the end of the initial string.

Also, because each of your if...then statements adds on an "AND ____" you need something to go before the first AND, so you don't end up with "WHERE AND blah=blah" in the final string. So after WHERE i put on something that should always be true, and now you'll get "WHERE p_id<>'' AND ____" (those are 2 single quotes after<>)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
advanced, search, form

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form output using mysql, search people name in specific category basketmen PHP Forum 1 Mar 24th, 2008 06:31
[SOLVED] Form Search longstand PHP Forum 6 Nov 20th, 2007 06:13
Help With Search Box/form William M Web Page Design 7 Oct 4th, 2007 16:02
Anyone have a working search form script? daveg33 PHP Forum 12 Sep 28th, 2007 23:54
osMax advanced search - product attributes geoffmuskett PHP Forum 0 Sep 9th, 2007 20:58


All times are GMT. The time now is 16:01.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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