Re: Advice On Building Dynamic MySQL Queries
| From: | Joe Brown | Date: | Fri, 20 Apr 2001 03:01:07 +0000 |
| Subject: | Re: Advice On Building Dynamic MySQL Queries | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-8741@lists.php.net to get a copy of this message | ||
My solution was almost as elegent...
$query="select * from customers";
$queryand=false;
if(!empty($f_Account)) {
$query.=" WHERE upper(P.Account) like upper('$f_Account')";
$queryand=true;
}
if(!empty($f_First_Name)) {
$query.=($queryand?" AND ":" WHERE ")."upper(p.First_Name) like
upper('$f_First_Name')";
$queryand=true;
}
...
For searchs, case doesn't matter (in my example), but you do need to index
your table accordingly for best results.
Also note upper() is the oracle uppercase function. I believe the uppercase
function varies from one RDBMS to another.
"Victor Foitzik" <vfoitzik@gmx.net> wrote in message
news:31232102796.20010420033835@gmx.net...
> Hello JD,
> on 19.04.2001 you wrote:
>
> > if (!empty($Price))
> > {
> > if(empty($whereclause))
> > {
> > $whereclause.="Price$Price";
> > }
> > else
> > {
> > $whereclause.=" AND 'Price $Price";
> > }
> > }
>
> and even better would be:
>
> if (!empty($$varname)) {
> $whereclause .= ($whereclause ? ' AND ' : '').
> "$varname =" . $$varname;
> }
>
> or something like this ;-)
>
> HTH
> Vic
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>