Re: PHP/MySQL question
| From: | Richard Lynch | Date: | Mon, 05 Jun 2006 16:07:09 +0000 |
| Subject: | Re: PHP/MySQL question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237407@lists.php.net to get a copy of this message | ||
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