PHP/MySQL question
| From: | Wolf | Date: | Mon, 05 Jun 2006 15:32:51 +0000 |
| Subject: | PHP/MySQL question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-237404@lists.php.net to get a copy of this message | ||
I have a php form that pulls data from the database (hence the problems)
I need to do an OR search on three columns, and AND the rest, anyone
have a good way to do this? So far my searching on the MySQL lists have
been fruitless more then anything, and I figured we've probably come
across this ourselves at some point.
Here's the code I have so far:
$query = "select * from honorclub";
if ($dead != "" || $unknown != "" || $name != "" || $county !=
"" ||
$year != "" || $countynow != "" || $state != "")
{$query .= " WHERE ";}
if ($dead == "")
{$query .= "
Deceased='N' AND";}
if ($unknown == "")
{$query .= " USPS_Unknown='N' AND ";}
if ($name != "")
{$query .= " Last_Name like '$name%' AND ";}
if ($county != "")
{$query .= " County like '$county' AND ";}
if ($year != "")
{$query .= " Year_Tapped like '$year' AND ";}
if ($countynow != "")
{$query .= " County_Now like '$countynow' AND ";}
if ($state != "")
{$query .= " State_Now like '$state' AND ";}
$query = rtrim($query," AND");
$query .= " order by $order_by";
What needs to be 'OR' is the $name section to be:
$query .= "Last_Name like '%$name%' OR First_Name like
'%$name%' OR
Maiden_Name like '%$name%'";
Thanks,
Wolf