$sql = "select * from table where 1 = 1";
$where = '';
if(!empty($条件一)){
$where .= " and 字段名=条件一的值";
}
if(!empty($条件二)){
$where .= " and 字段名=条件二的值";
}
………
if(!empty($条件N)){
$where .= " and 字段名=条件N的值";
}
echo $sql.$where;
正常来讲输出 sql 应该是:
select * from table where 1 = 1 and 字段名1 = 条件一的值 and 字段名2 = 条件二的值 and …… and 字段N = 条件N的值;