Page 1 of 1

help with if and else statement

Posted: Mon Mar 22, 2004 2:37 am
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";
}
####################################

Posted: Mon Mar 22, 2004 3:46 am
by McGruff
Two forms?

Posted: Mon Mar 22, 2004 3:59 am
by mnleach
would look better with just the one, must be able to be done, i would think.

Posted: Mon Mar 22, 2004 4:35 am
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";
}

re

Posted: Mon Mar 22, 2004 5:06 am
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