help with if and else statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mnleach
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2004 2:37 am

help with if and else statement

Post by mnleach »

Hi,
I run a real estate office, and am doing a new property search page, and have added a Reference No. search, extra to an area, type, bedrooms and price one that is already working ok.
I am having trouble getting the right statement working.
I need the script to work, that if someone asks for a ref.no search, it cancels out them picking any other search eg: bedrooms area etc.
So basically, if they pick an area search they cannot pick a ref.no. search, but if they pick a ref.no search it shows that property with that ref.no.
Hope someone can help.
The bit i have tried to implement is between the #####
The code above it works ok without the ref.no bit.

Code: Select all

//echo "area=$area type=$type bedromms=$bedrooms price=$price ref=$ref dsds=$saklj ";
$querytmp="select * from prop";
$where=0;
if ($area !=0)
{
	$querytmp.=" where area=$area";
	$where=1;
}
if ($type !=0)
{
	if ($where == 0)
	{
		$querytmp.=" where";
		$where=1;
	}
	else
	{
		$querytmp.=" and";
	}
	$querytmp.=" type=$type";
}
if ($bedrooms !=0)
{
	if ($where == 0)
	{
		$querytmp.=" where";
		$where=1;
	}
	else
	{
		$querytmp.=" and";
	}
	$querytmp.=" bedrooms=$bedrooms";
}
###################
if ($ref !=0)
{
if ($where == 0)
	{
		$querytmp.=" where";
		$where=0;
	}
	else
	{
		$querytmp.=" and";
	}
	
	
	$querytmp.=" ref=$ref";
}
####################################
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Two forms?
mnleach
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2004 2:37 am

Post by mnleach »

would look better with just the one, must be able to be done, i would think.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You are only checking for numeric values - is that correct?
If not, try using

Code: Select all

if (!empty($ref))
{
if (empty($where))
   {
      $querytmp.=" where";
   }
   else
   {
      $querytmp.=" and";
   }
   
   
   $querytmp.=" ref=$ref";
}
mnleach
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2004 2:37 am

re

Post by mnleach »

Tried it , coming up that it has not found the ref.no.
Some of the ref.no. are numerical and some are letters.
Rest of the search works ok still
Post Reply