Jump to content


Photo

searching for some or everything


  • Please log in to reply
2 replies to this topic

#1 JayNo

JayNo
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationToronto

Posted 27 February 2006 - 07:08 PM

I'm having trouble searching for things from my database.

I have a drop down list of clients, eg..
- all clients <initially selected>
- Asahi
- Budweiser
- Corona
- Heineken

if the user doesn't select anything I want to search for everything in the database no matter what the client name. If a client is selected i want it to search for data from only that client. The only problem is that there is about 20 other fields that have areas like this (so i can't just set up a different query for each)

Anyone have an idea as to how to set up a search function to do this.

My code right now looks like this:

$client = $_POST['client'];
if ($client == 'All'){
  $clientCompare = "NOT IN ('$client')";
}else{
  $clientCompare = "= '$client'";
}
mysql_select_db($mysqldatabase, $mysqlconnection);
$exhibitQuery = "SELECT * FROM tbl_test1 WHERE col_clientName $clientCompare";
Right now this works but only when there is a client selected on the form. but if i put in the "NOT IN()" directly into the WHERE clause it works... this is where i'm frustrated.

I will need other conditions for the other form data, but just testing right now.

Thanks.

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 February 2006 - 08:15 PM

$client = $_POST['client'];
if ($client == 'All'){
  $clientCompare = "%";
}else{
  $clientCompare = "$client";
}
mysql_select_db($mysqldatabase, $mysqlconnection);
$exhibitQuery = "SELECT * FROM tbl_test1 WHERE col_clientName LIKE '$clientCompare'";

Try that

Ray

#3 JayNo

JayNo
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationToronto

Posted 27 February 2006 - 08:30 PM

Thank you Ray, this will probably be the answer for the other fields too. Would this work for numbers as well?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users