Need help with PHP & MySQL
by Berk/Devlin <armadill(at)earthlink.net>
|
Date: |
Mon, 13 May 2002 09:38:46 -0700 |
To: |
hwg-techniques(at)mail.hwg.org |
Cc: |
zibbler(at)web-design-cs.com |
In-Reply-To: |
|
|
todo: View
Thread,
Original
|
|
See answers, below.
On Fri, 3 May 2002 18:10:17 -0400, "Lisa Bradshaw" <zibbler(at)web-design-cs.com> asked:
>Any PHP & MySQL gurus out there?
Yup.
>... So for instance if I was looking for a seafood restaurant in Dade county, but didn't enter a selection for alpha or price, in theory it should return records for ALL seafood reataurants in Dade county regardless of alpha or price. Following is the code I'm using to query the database:
>
>$result=mysql_query("SELECT * FROM
>Restaurants WHERE County='$county' AND Alpha='$alpha' AND Cuisine='$cuisine'
>AND Price='$price' ORDER BY Name");
>
>How can I get it to ignore the blank variables and pass the info? Is this
>even possible?
ANYTHING is possible in PHP.
>... It's seeing $county as "", and because there is no "" listed in the database for County, it of course returns no records. Any way around this? This is my first attempt at using PHP and MySQL.HELP!!!
Lisa, what you need is an if statement. Something like this:
<?
$result=mysql_query("SELECT * FROM Restaurants WHERE
<? if ($county <> ""):
print "County='$county' AND ";
endif;
?> Alpha='$alpha' AND Cuisine='$cuisine' AND Price='$price' ORDER BY Name");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Emily Berk ~
On the web at www.armadillosoft.com *** Armadillo Associates, Inc. ~
~ Project management, developer relations and ~
extremely-technical technical documentation that developers find useful.~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA