Re: PHP Problem: If else statement
by "Keith Sellars" <Keith(at)webgraffix.com>
|
| Date: |
Thu, 13 Jun 2002 14:03:56 -0400 |
| To: |
"HWG" <hwg-languages(at)hwg.org> |
| References: |
rkwinternet |
| |
todo: View
Thread,
Original
|
|
Replace
if ($bedrooms = 'NULL') {
with
if ($bedrooms != '') {
I believe that will do what you are seeking. Someone correct me if I am
wrong, please.
Thanks,
Keith D Sellars
WebGraffix
www.webgraffix.com
"Making database sites seem easy"
----- Original Message -----
From: "Richard Williams" <richard(at)rkwinternet.com>
To: "HWG" <hwg-languages(at)hwg.org>
Sent: Thursday, June 13, 2002 1:13 PM
Subject: PHP Problem: If else statement
> Hi
>
> I'm using a form (search.php) to return a set of results from a mysql
database (results.php). The address is:
> www.burton-property.co.uk/search.php
>
> The search is governed by what's in two fields: bedrooms and price_id.
>
> It's been working fine, but now the client wants a set of results returned
whereby if the visitor leaves the bedrooms field in the
> form empty the results.php page will return ALL results that match the
price_id field.
>
> So, for example, if the selected price range is £75,001 - £100,000
(price_id = 3) and the bedrooms parameter is null then ALL
> properties with a price_id of 3 will be returned regardless of the number
of bedrooms that particular property has.
>
> But I can't get it to work! Here is the bit of code I'm having trouble
with...
>
> ==============================
>
> if ($bedrooms = 'NULL') {
>
> $result = mysql_query("SELECT advert, property, price, description,
bedrooms, price_id, P_No FROM adverts WHERE price_id =
> '$price_id'"); }
>
> else {
>
> $result = mysql_query("SELECT advert, property, price, description,
bedrooms, price_id, P_No FROM adverts WHERE price_id =
> '$price_id' AND bedrooms = '$bedrooms'"); }
>
> ===============================
>
> If I select price range £75,001 - £100,000 (price_id = 3) and leave the
bedrooms field empty I get a good result (the first and last
> results are wrong because of inputting errors to the database).
>
> However, if I put in a figure of say 3 for the bedrooms field the results
bring up properties with 2 and 4 bedrooms as well!
>
> I've been working on this all afternoon and it's driving me nuts, so if
anyone can help I'd be ecstatic!
>
> Cheers
>
> Richard Williams
>
>
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.