Re: PHP Problem: If else statement

by sstahl(at)shaw.ca

 Date:  Thu, 13 Jun 2002 12:51:15 -0600
 To:  richard(at)rkwinternet.com
 Cc:  HWG <hwg-languages(at)hwg.org>
  todo: View Thread, Original
Your if statement should be=3A

 if (=24bedrooms =3D=3D =27=27) =7C=7C (=24bedrooms =3D=3D =27 =27) =7B

Scott=2E

----- Original Message -----
From=3A Richard Williams =3Crichard=40rkwinternet=2Ecom=3E
Date=3A Thursday=2C June 13=2C 2002 11=3A13 am
Subject=3A PHP Problem=3A If else statement

=3E Hi
=3E =

=3E I=27m using a form (search=2Ephp) to return a set of results from a =

=3E mysql database (results=2Ephp)=2E The address is=3A
=3E www=2Eburton-property=2Eco=2Euk/search=2Ephp
=3E =

=3E The search is governed by what=27s in two fields=3A bedrooms and pric=
e=5Fid=2E
=3E =

=3E It=27s been working fine=2C but now the client wants a set of results=
 =

=3E returned whereby if the visitor leaves the bedrooms field in the
=3E form empty the results=2Ephp page will return ALL results that match =

=3E the price=5Fid field=2E
=3E =

=3E So=2C for example=2C if the selected price range is =A375=2C001 - =A3=
100=2C000 =

=3E (price=5Fid =3D 3) and the bedrooms parameter is null then ALL
=3E properties with a price=5Fid of 3 will be returned regardless of the =

=3E number of bedrooms that particular property has=2E
=3E =

=3E But I can=27t get it to work! Here is the bit of code I=27m having =

=3E trouble with=2E=2E=2E
=3E =

=3E =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
=3E =

=3E 	  if (=24bedrooms =3D =27NULL=27) =7B
=3E =

=3E      =24result =3D mysql=5Fquery(=22SELECT advert=2C property=2C pric=
e=2C =

=3E description=2C bedrooms=2C price=5Fid=2C P=5FNo FROM adverts WHERE pr=
ice=5Fid =3D
=3E =27=24price=5Fid=27=22)=3B =7D
=3E =

=3E 	  else =7B
=3E =

=3E 	  =24result =3D mysql=5Fquery(=22SELECT advert=2C property=2C price=2C=
 =

=3E description=2C bedrooms=2C price=5Fid=2C P=5FNo FROM adverts WHERE pr=
ice=5Fid =3D
=3E =27=24price=5Fid=27 AND bedrooms =3D =27=24bedrooms=27=22)=3B =7D
=3E =

=3E =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
=3E =

=3E If I select price range =A375=2C001 - =A3100=2C000 (price=5Fid =3D 3)=
 and =

=3E leave the bedrooms field empty I get a good result (the first and las=
t
=3E results are wrong because of inputting errors to the database)=2E
=3E =

=3E However=2C if I put in a figure of say 3 for the bedrooms field the =

=3E results bring up properties with 2 and 4 bedrooms as well!
=3E =

=3E I=27ve been working on this all afternoon and it=27s driving me nuts=2C=
 =

=3E so if anyone can help I=27d be ecstatic!
=3E =

=3E Cheers
=3E =

=3E Richard Williams
=3E =

=3E 

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA