时间:2021-07-01 10:21:17 帮助过:18人阅读
foreach(array_diff($_POST, array('')) as $k=>$v)
$r[] = "$k='$v'";
$sql = "select * from student where ". join(' and ', $r);
------解决方案--------------------
应该是,上面少给一个''
$sql="select * from student where 1=1"; if(!empty($_POST['name'])) $sql=" and name='$_POST[name]'"; if(!empty($_POST['age'])) $sql=" and age='$_POST[age]'"; if(!empty($_POST['sex'])) $sql=" and sex='$_POST[sex]'"; if(!empty($_POST['height'])) $sql=" and height='$_POST[height]'";