时间:2021-07-01 10:21:17 帮助过:54人阅读
可以参考一下写法
$where = array();if($board){ $where[]=" board='$board'";}if($year){ $where[]=" year='$year'";}....$sql.=(!empry($where)) ? ' where ' . implode(' and ', $where) : '';
设提交后 $_POST 为
$_POST = array('board' => 'BMW', 'year' => '2013', 'type' => '');
则
$w = array();
foreach($_POST as $k=>$v) {
if(! empty($v)) $w[] = "$k='$v'";
}
$where = join(' and ', $w);
得到
board='BMW' and year='2013'