Jump to content

Parsing multiple Check boxes for advanced search


hybmg57

Recommended Posts

Hi,

 

I currently have a hard time passing checkbox variables (School Types elementary, middle, high) from a search page to results page. I tried to put some if statements to adjust MySQL commands but it's not working well... Anyone has any ideas?

 

$Property_Type=$_GET['property_type'];
$City=$_GET['city'];
$Beds=$_GET['beds'];
$Baths=$_GET['baths'];
$Lowest_Price=$_GET['lowest_price'];
$Highest_Price=$_GET['highest_price'];
$MLS=$_GET['mls_number'];
$CityA=$_GET['citya'];
$AddressA=$_GET['address'];
$Zip_codeA=$_GET['zip_code'];
$SubdivisionA=$_GET['subdivision'];
$GarageA=$_GET['garage'];
$StoriesA=$_GET['stories'];
$FireplacesA=$_GET['fireplaces'];
$Yard_sizeA=$_GET['yard_size'];
$CitiesA=$_GET['cities'];
$AreasA=$_GET['areas'];
$CountiesA=$_GET['counties'];
$School_districtA=$_GET['school_district'];
$School_type_elementaryA=$_GET['school_type'];
$School_type_middleA=$_GET['school_type'];
$School_type_highA=$_GET['school_type'];
$School_nameA=$_GET['school_name'];

$E = $School_type_elementaryA['elementary'][0];
$M = $School_type_middleA['middle'][0];
$H = $School_type_highA['high'][0];
if ($E == "E" || $M == "M" || $H == "H"){
if ($E == "E" && $M == "M" && $H == "H"){
	$School_type = "SCHOOLTYPE1 LIKE 'E' AND SCHOOLTYPE2 LIKE 'M' AND SCHOOLTYPE3 LIKE 'H'";
}
if ($E == "E" && $M == "M" && empty($_GET['school_type']['high'])){
$School_type = "SCHOOLTYPE1 LIKE 'E' AND SCHOOLTYPE2 LIKE 'M'";
}
if (empty($_GET['school_type']['elementary']) && $M == "M" && $H == "H"){
$School_type = "SCHOOLTYPE2 LIKE 'M' AND SCHOOLTYPE3 LIKE 'H'";
}
if ($E == "E" && empty($_GET['school_type']['middle']) && $H == "H"){
	$School_type = "SCHOOLTYPE1 LIKE 'E' AND SCHOOLTYPE3 LIKE 'H'";
}
if ($E == "E" && $M == NULL && $H == NULL){
	$School_type = "SCHOOLTYPE1 LIKE 'E'";
}
if ($M == "M"&& $E == NULL && $H == NULL){
	$School_type = "SCHOOLTYPE2 LIKE 'M'";
}
if ($H == "H"&& $E == NULL && $M == NULL){
	$School_type = "SCHOOLTYPE3 LIKE 'H'";
}
$School_type = "SCHOOLTYPE3 LIKE 'H'";

$result = mysql_query("SELECT * 
					FROM residential 
					WHERE	PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%'
					AND	AREA {$Any_City} {$City}
					AND	BEDS >={$Beds}
					AND	BATHSTOTAL >={$Baths}
					AND	LISTPRICE >={$Lowest_Price}
					AND	LISTPRICE {$Any} {$Highest_Price}
					AND	CITY LIKE '%{$CityA}%'
					AND STREETNAME LIKE '%{$AddressA}%'
					AND ZIPCODE {$Any_Zip} '{$Zip_codeA}'
					AND SUBDIVISION LIKE '%{$SubdivisionA}%'
					AND GARAGECAP	>=	{$GarageA}
					AND STORIES		>=	{$StoriesA}
					AND	FIREPLACES	>=	{$FireplacesA}
					AND LOTSIZE		{$Yard}
					AND SCHOOLDISTRICT LIKE '%{$School_districtA}%'
					AND SCHOOLNAME1 LIKE '%{$School_nameA}%'
					AND SCHOOLNAME2 LIKE '%{$School_nameA}%'
					AND SCHOOLNAME3 LIKE '%{$School_nameA}%'
					AND {$School_type}


					ORDER BY {$sort}
					LIMIT {$offset}, {$limit}")
or die(mysql_error());

Link to comment
Share on other sites

The error I'm getting is "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY MODIFIED ASC LIMIT 0, 20' at line 24"

 

Thank you.

Link to comment
Share on other sites

When you have a syntax error, echoing the submitted query statement usually helps.

 

For that reason I always assign my statements to a variable which can then be easily echoed.

 

EG

$sql = "SELECT something FROM atable";
$res = mysql_query($sql) or die (mysql_error() . "<pre>$sql</pre>");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.