hybmg57 Posted July 7, 2010 Share Posted July 7, 2010 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()); Quote Link to comment https://forums.phpfreaks.com/topic/206946-parsing-multiple-check-boxes-for-advanced-search/ Share on other sites More sharing options...
hybmg57 Posted July 7, 2010 Author Share Posted July 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206946-parsing-multiple-check-boxes-for-advanced-search/#findComment-1082211 Share on other sites More sharing options...
Barand Posted July 8, 2010 Share Posted July 8, 2010 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/206946-parsing-multiple-check-boxes-for-advanced-search/#findComment-1082985 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.