View Single Post
  #1 (permalink)  
Old 07-10-05, 01:15 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Search database with multiple AND problem

Hello

I am building a search page and have hit a bit of a problem.

I built the original search using either an error code search or symptom search; if one or the other field was empty it used a different query :
PHP Code:

if ( $error ''){

$result=MYSQL_QUERY(" SELECT * FROM hardware WHERE error='$error' ORDER BY referance "
or die (
mysql_error());
}

elseif ( 
$symptom ''){
$result=MYSQL_QUERY(" SELECT * FROM hardware WHERE symptom='$symptom' ORDER BY referance "
or die (
mysql_error());
}

else { echo 
"No search terms entered. Press back on your browser";} 
Then I tried expanding this to 4 form inputs and the user could just fill in the information he knew. But the problem is that I have to have ALL the fields matching a result to get an answer and the user can not leave anything blank.

Can somebody please tell me where I am going wrong?
PHP Code:

$result=MYSQL_QUERY("SELECT * FROM hardware WHERE symptom='$symptom' AND manufacturer = '$manufacturer'AND

 component = '
$component' ORDER BY referance"
or die (
mysql_error()); 
Anthony
Reply With Quote