Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching a MySQL DB

Status
Not open for further replies.

doddo

Programmer
Feb 14, 2001
37
GB
Hi, I am writing a CGI script where a user searches a DB using a combination of up to 10 different criteria. However, if the user leaves a search criteria blank I don't want the program to search using it, obviously. Is there a way of saying:

select all matches in field1 if the field1 param was selected, and all matches in field2 if the field2 param was selected and all matches in field3 if the field3 param was selected etc,etc

thanks in advance
rich
 
I would suggest building the SQL statement on the fly.

in VBscript it would look like:

strSQL = "SELECT * FROM table WHERE "

if field1 <> &quot;&quot; then strSQL = strSQL & &quot; field1='&quot; & field1.value & &quot;', &quot;

if field2 <> etc...

At the end, with a bit of luck, strSQL should look pretty bloody good.:) Steve Davis
hey.you@hahaha.com.au
 
Microbe,
thanks very much, very useful

cheers
Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top