help need 4 Search function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
minos_mks
Forum Commoner
Posts: 69
Joined: Thu Feb 04, 2010 1:58 am

help need 4 Search function

Post by minos_mks »

function select_ads_search ($tablename,$per_page,$start,$order,$search_or_no,$disc,$has_pic,,$min_price,$max_price)
{ global $connection;

$query = " SELECT * ";
$query .= " from $tablename ";
$query .= " where activation = 1";

if ($has_pic == 0 )
{
$query .= " and has_pic = 0" ;
// echo "</br>$query</br>";
}
else
{
$query .= " and has_pic = 1" ;
}
if (isset ($min_price) and isset ($max_price) )
{ //echo "min_price:$min_price</br>" ;
$query .= " and price BETWEEN $min_price AND $max_price" ;
echo "</br>$query</br>";
}
if (isset ($min_price) && !isset ($max_price) )
{
$query .= " and price >= $min_price" ;
echo "</br>$query</br>";
}
if (!isset ($min_price) && isset ($max_price) )
{
$query .= " and price <= $max_price" ;
echo "</br>$query</br>";
}

$query .= " order by $order DESC ";
//$query .= " ORDER BY ad_S_DATE DESC";
$query .= " LIMIT $start , $per_page ";
//echo $query;
$result_ads = mysql_query($query,$connection);
confirm_query($result_ads);
return $result_ads;
}


i make this function as search like the one on craglist but i don't know why alwas go insed the hielited if even if the $max_price is not set ,
it's like i have to field on the page on 4 the max price and one 4 the min price and there is 3 propapilte 4 the user respons :
A- the user enterd the max price only
b- the user enterd the min price only
c- the user enterd the max price and the min price

So can any one help my on this
Post Reply