拼接查询
$where = "where 1=1";
if($_GET['a']){
$where .= " AND a =".$_GET['a'];
}elseif($_GET['b']){
$where .= " AND b =".$_GET['b'];
}
$where = "where 1=1";
if($_GET['a']){
$where .= " AND a =".$_GET['a'];
}elseif($_GET['b']){
$where .= " AND b =".$_GET['b'];
}
关键字 $a,$b,$c............$n
if($a)$data['a'] = $a;
if($b)$data['b'] = $b;只要判断$data数组是否有内容就行了
$condition = "name=$_POST['keywords']";
}else{
$condition = "1=1";
}
$sql = "select * from tb where $condition";