Forum Moderators: coopster

Message Too Old, No Replies

Debugging - please help :(

         

adammc

12:30 am on Nov 21, 2007 (gmt 0)

10+ Year Member



Hi guys,

Can anyone please help me debug this?
My script broke and I cant for the life of me work out why?

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 city in ('SANDGATE','SAMSONVALE')' at line 1

else if(($mode == 'search')) {

echo"<br />";
///*********** Search Code goes here **************////////////////

$select_list = " select * ";
$from_list = " from Links lnk";
$where_list = " where state='$_GET[state]' and validated='1' order by business_name ASC";

if($_GET['category'])
{
$category = $_GET['category'];
$cat_query = mysql_query("SELECT cat_id from Categories where category_name like '".$category."'") or die(mysql_error());
$num_rows = mysql_num_rows($cat_query);
$r = mysql_fetch_assoc($cat_query);
$category_id =$r['cat_id'];
$where_list .= " and lnk.category_id = '".$category_id."'";
}

if($_GET['postcode'])
{
$post_code = $_GET['postcode'];
$where_list .= " and lnk.postcode = '".$post_code. "' ";
}

if($_GET['tb'])
{
$suburb_array = explode(', ',$_GET['tb']);
$suburb_count = count($suburb_array);
//echo "\n the number of elements in the aray is : ".$suburb_count;
$suburb_list = '';
if($suburb_count > 1 )
{
for($i=0;$i<$suburb_count-1; $i++)
{
$suburb_list .= "'".ltrim(rtrim($suburb_array[$i],','),' ')."'";
if($i < $suburb_count-2)
$suburb_list .= ",";
}
// join the list with an and conidtion!
$where_list .= " and city in (".$suburb_list.")";
}

}

$query = $select_list . $from_list . $where_list;

// $gen-query will have the genrated query!
$gen_query = $query;

///*********** Search Code goes here **************////////////////
/* call the database and check for dusplay of right results here */
/* included the genrated query to genrate the results here */
$query = mysql_query($gen_query) or die(mysql_error());
$num_rows = mysql_num_rows($query);
if (empty($num_rows))
{
echo "Your search has returned no results.<br />Try your <a href=\"javascript:history.go(-1)\">search again</a>";
} else {

adammc

2:18 am on Nov 21, 2007 (gmt 0)

10+ Year Member



I got it sorted, I guess my 'order by' was in the wrong spot in the code.

$orderby = " order by business_name ASC";
$query = $select_list . $from_list . $where_list . $orderby;

Thanks for your help :)