$where = array();
if(!empty($type)){
   $where[] = " `type` = ".$type ;
}
if(!empty($price)){
   $where[] = " `price` = ".$price ;
}
if(!empty($area)){
   $where[] = " `area` = ".$area ;
}
if(!empty($where)){
   $where = implode(' And ',$where);
   $sql = " SELECT * FROM `table` Where ".$where;
}else{
   $sql = "SELECT * FROM `table` "; 
}

当$where数组中只有一个元素时

假定:$where=array('name’);

implode(' and ',$where);//返回的只是字符串name,不带and

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2021-06-29
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2021-06-11
  • 2021-12-14
  • 2022-12-23
  • 2022-02-04
  • 2021-10-27
相关资源
相似解决方案