RE: PHP Problem: If else statement

by "jeremy" <jeremy(at)localnetamerica.com>

 Date:  Thu, 13 Jun 2002 13:55:08 -0400
 To:  <richard(at)rkwinternet.com>,
"'HWG'" <hwg-languages(at)hwg.org>
 In-Reply-To:  rkwinternet
  todo: View Thread, Original
I just used your form, and whether I leave the # of bedrooms blank, set
it equal to 3 or to 93, I still receive the same property(ies) in the
result.  I believe this is being caused by your=20

	  if ($bedrooms =3D 'NULL') {

line.  You need to check for $bedrooms value by using a double equals,
like =3D=3D.  Therefore, the code should read

	if($bedrooms=3D=3D'NULL') {


Another thing which may or may not be the problem, is checking for a
NULL value in bedrooms.  I could be mistaken, but NULL values exist if
the variable has never been set.  Since $bedroom is being set, whether
left blank or filled in, $bedroom should be checked against an empty
value like:

	If($bedroom=3D=3D"") {

Hope this helps.  If it doesn't, send another post and I'll do some more
research.

Regards


Jeremy Brown
Director of Web Technology
Hafenbrack Marketing and Communications
http://www.hafenbrack.com
(937) 859-0730

-----Original Message-----
From: owner-hwg-languages(at)hwg.org [mailto:owner-hwg-languages(at)hwg.org]
On Behalf Of Richard Williams
Sent: Thursday, June 13, 2002 1:14 PM
To: HWG
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 =A375,001 - =A3100,000
(price_id =3D 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...

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

	  if ($bedrooms =3D 'NULL') {

      $result =3D mysql_query("SELECT advert, property, price,
description, bedrooms, price_id, P_No FROM adverts WHERE price_id =3D
'$price_id'"); }

	  else {

	  $result =3D mysql_query("SELECT advert, property, price,
description, bedrooms, price_id, P_No FROM adverts WHERE price_id =3D
'$price_id' AND bedrooms =3D '$bedrooms'"); }

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

If I select price range =A375,001 - =A3100,000 (price_id =3D 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.