thank you for the good tips. I fixed the query. Here is my final code after modifcation.
$search = '';
$the_array = explode(' ', $q);
$i = 0;
foreach( $the_array AS $t ){
if( $i == 0 ){
$search .= " '%$t%' ";
$i = 1;
}else{
$search .= " OR listname LIKE '%$t%' ";
}
}
$query = "select listid,cid,listname,city,state,country,postcode,website ";
$query.="FROM yp_list where listname like $search ";
if(!empty($cid) && $cid !='ANY') {
$query .= "AND cid like '%$cid%' ";
}
if(!empty($state)) {
$query .= "AND state like '%$state%' ";
}
if(!empty($city)) {
$query .= "AND city like '%$city%' ";
}
if(!empty($postcode)) {
$query .= "AND postcode like '%$postcode%' ";
}
if(!empty($country) && $country !='ANY') {
$query .= "AND country like '%$country%' ";
}
echo"$query<br><br>";
$result = mysql_query($query,$dbi) or die ("Error".mysql_error());
$num_record = mysql_num_rows($result);
if i search in category "Acccountant" Which id is 74, City"Auckland" and country 'New zealand' whose id is 153.
I get this query
select listid,cid,listname,city,state,country,postcode,website FROM yp_list where listname like '%ANZ%' OR listname LIKE '%Bank%' AND cid like '%74%' AND city like '%Auckland%' AND country like '%153%'
I should get only one result.
I have two records as follow
ANZ Bank,Auckland,New Zealand in category' Accountant'
ANZ Bank,Sydney,Australia in category' Accountant'
so when i search for ANZ Bank in city(Auckaland) and Country New Zealand.. i should get only one records.But I am getting two records.
Any suggestion.. basicly I want in search function .. i can choose one category or all category,one location or all or one country or all etc..
One example..
http://www.yellowmaker.com/cgi-bin/yellowmaker/se/advanced.pl
Thanks