RE: PHP Problem: If else statement

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

 Date:  Thu, 13 Jun 2002 16:23:19 -0400
 To:  <richard(at)rkwinternet.com>,
<sstahl(at)shaw.ca>
 Cc:  "'HWG'" <hwg-languages(at)hwg.org>
 In-Reply-To:  rkwinternet
  todo: View Thread, Original
The second alternative is going to check to see if the user typed a
space (pressed the space key) in the box.  So not only are you checking
to see if it contains no value, you're also checking to see if it
contains a space (which is visually equal to no value).  If you wanted
to check to see if a space or any number of spaces had been entered, you
could write a small piece of code that would evaluate the variable for
multiple occurrences of a space.

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 3:12 PM
To: sstahl(at)shaw.ca
Cc: HWG
Subject: RE: PHP Problem: If else statement

Thanks Scott, but why the second alternative? I did wonder what the
effect of '' and ' ' would be. Although, so far, I've used "".

I think I'm really going to enjoy belonging to this group, but it may be
a while before I get to contribute for others benefit! :)

Cheers

Richard Williams

> -----Original Message-----
> From: sstahl(at)shaw.ca [mailto:sstahl(at)shaw.ca]
> Sent: 13 June 2002 19:51
> To: richard(at)rkwinternet.com
> Cc: HWG
> Subject: Re: PHP Problem: If else statement
>
>
> Your if statement should be:
>
>  if ($bedrooms =3D=3D '') || ($bedrooms =3D=3D ' ') {
>
> Scott.
>
> ----- Original Message -----
> From: Richard Williams <richard(at)rkwinternet.com>
> Date: Thursday, June 13, 2002 11:13 am
> 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
> >
> >
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 05/06/02
>

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.