Re: PHP/MySQL question

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

 



On Mon, June 5, 2006 10:32 am, Wolf wrote:
> 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:

I'm confused just by the indenting (or lack thereof) but one standard
technique is to start off with a "yeast" such as:

$query = "select * from honorclub "; //Fix * to be actual columns!
$query .= " WHERE 1 ";
if ($dead != "" ...){
  $query .= " AND Deceased = 'N' ";
}
$query .= " AND (First_name like '%$name%' or Last_name like '%$name%'
) ";

> $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
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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