Re: Need help with PHP & MySQL
by "Lisa Bradshaw" <zibbler(at)web-design-cs.com>
|
|
Darrell! A thousand thank yous!!! You made my day :-) It works just as I
wanted it to! I just hope my hair grows back soon ;-) I ordered a good book
on PHP & MySQL from amazon, so hopefully I'll get it in the next couple of
days. I have a Dummies book on PHP & MySQL which is absolutely useless...
390 pages of fluff. Oh well, I should know better than to use a Dummies
book.
Thanks again!
Lisa
----- Original Message -----
From: "Darrell King" <darrell(at)webctr.com>
To: <hwg-techniques(at)hwg.org>
Sent: Friday, May 03, 2002 9:36 PM
Subject: Re: Need help with PHP & MySQL
> When you have multiples like that, you need to first check whether there
> should even by a WHERE in the query. If all the clauses are empty, then
the
> WHERE stands alone and that is a BAD thing.
>
> Try this:
>
> $where_clause=Array();
>
> if (isset($alpha)&&!empty($alpha)) $where_clause[] =" Alpha='$alpha' ";
> if (isset($county)&&!empty($county)) $where_clause[] =" County='$country'
";
> if (isset($cuisine)&&!empty($cuisine)) $where_clause[] ="
Cuisine='$cuisine'
> ";
> if (isset($price)&&!empty($price)) $where_clause[] =" Price='$price' ";
>
> if (sizeof($where_clause)) {
> $final_where_clause=" WHERE ".join(" AND ",$where_clause);
> }
>
> $result=mysql_query(
> "SELECT *
> FROM Restaurants
> $final_where_clause
> ORDER BY Name
> ");
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA