SQL Search Results

I am trying to do a search page but am having a bit of trouble.


if(isset($country)) {
$search_co =“WHERE list_country = ‘$country’”; } else { $search_co="";}
if(isset($state)) {
$search_st =“AND list_province = ‘$state’”; } else { $search_st="";}
if(isset($region)) {
$search_re =“AND list_region = ‘$region’”; } else { $search_re="";}
if(isset($property)) {
$search_lpt =“AND list_prop_type = ‘$property’”; } else { $search_lpt="";}
if(isset($prop_sleeps)) {
$search_psl =“AND list_sleeps = ‘$prop_sleeps’”; } else { $search_psl="";}
if(isset($prop_pool)) {
$search_prpool =“AND list_pri_pool = ‘$prop_pool’ OR list_share_pool = ‘$prop_pool’”; } else { $search_prpool="";}
if(isset($prop_pets)) {
$search_prpet =“AND list_pets = ‘$prop_pets’”; } else { $search_prpet="";}
if(isset($hol_type)) {
$searchprholty =“AND list_cat = ‘$hol_type’”; } else { $searchprholty="";}

$sql =“SELECT * FROM listings $search_co $search_co $search_st $search_re $search_lpt $search_psl $search_prpet $searchprholty $search_prpool”;


I am getting the following error

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 'AND list_prop_type = '' AND list_sleeps = '' AND list_pets = ''

Anyone have any suggestions

i have 2 suggestions:

  1. the WHERE shouldn’t be included in $search_co, because if $country is not set there will be no where

  2. put a echo($sql) right after the $sql=… line.


I have dumped the if isset and gone for

if($value == “”)

It seems to be working

as for the WHERE in the country field, its a requires field in a previous page so has to be set

Thanks anyway

Sponsor our Newsletter | Privacy Policy | Terms of Service