ברור- נתתי לך הסבר לגבי הטבלאות איך צריך לבנות אותם. מכאן השאילתות מאוד פשוטות..
PHP קוד:
/**
* Build custom where statment by the post request
*
* @param array $post
* @return string $where
*/
function _custom_build_where($post=null) {
if($post==null) $post=$_POST;
$where = "";
$and = false;
if(!empty($post['name'])) {
if($and) $where.=" AND";
$where .= " `name`='" . mysql_real_escape_string($post['name'])."'";
}
if(!empty($post['city'])) {
if($and) $where.=" AND";
$where .= " `city_id`='" . intval($post['city']);
}
if(!empty($post['zone'])) {
if($and) $where.=" AND";
$where .= " `zone_id`='" . intval($post['zone']);
}
return $where;
}
$where = _custom_build_where($_POST);
$query = "SELECT * FROM `prefix_card` WHERE " . $where . ";";
echo $where;