PHP/MySQL question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux