# SQL Search Results

**URL:** <https://www.phphelp.com/t/sql-search-results/10280>\
**Category:** General PHP Help\
**Created:** [September 3, 2007, 5:17pm UTC](https://www.phphelp.com/t/sql-search-results/10280 "2007-09-03T17:17:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyd34](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@andyd34](https://www.phphelp.com/u/andyd34)\
**Post date:** [September 3, 2007, 5:17pm UTC](https://www.phphelp.com/t/sql-search-results/10280/1 "2007-09-03T17:17:55Z")

</div>

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

[php]

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”;

[/php]

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

---

<div class="post-metadata">

**Author:** ![Q1712](https://www.phphelp.com/letter_avatar_proxy/v4/letter/q/a183cd/32.png) [@Q1712](https://www.phphelp.com/u/Q1712)\
**Post date:** [September 3, 2007, 5:30pm UTC](https://www.phphelp.com/t/sql-search-results/10280/2 "2007-09-03T17:30:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andyd34](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@andyd34](https://www.phphelp.com/u/andyd34)\
**Post date:** [September 3, 2007, 8:09pm UTC](https://www.phphelp.com/t/sql-search-results/10280/3 "2007-09-03T20:09:07Z")

</div>

Hi

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
