Hey, I can't quite figure out how to do a multiple WHERE using AND and also using OR in my SQL statement. Here's the example:
mysql_query("SELECT * FROM mel_spysupply.clients WHERE clients_subof IS NULL AND clients_tstamp > $fromDate AND clients_tstamp < $toDate AND clients_fn LIKE '%$_POST[search_criteria]%' OR clients_ln LIKE '%$_POST[search_criteria]%' OR clients_company LIKE '%$_POST[search_criteria]%' OR clients_address LIKE '%$_POST[search_criteria]%' OR clients_city LIKE '%$_POST[search_criteria]%' ORDER BY $sortBy ASC") or die(mysql_error());
Basically, I'm trying to figure out how I can get mySQL to understand that I have three groups of WHEREs
Group 1 always returns WHERE: "clients_subof IS NULL"
Group 2 always returns WHERE: "clients_tstamp > $fromDate AND clients_tstamp < $toDate"
Group 3 always returns ONE OF THESE: " clients_fn LIKE '%$POST[search_criteria]%' OR clients_ln LIKE '%$POST[search_criteria]%' OR clients_company LIKE '%$POST[search_criteria]%' OR clients_address LIKE '%$POST[search_criteria]%' OR clients_city LIKE '%$_POST[search_criteria]%'"
However, it gets confused with the way I have it above and it never searches the dates right when I have the OR statements in there. However, if I remove the OR statements, the date works perfectly.
Any ideas?
Thanks!!