sql中对于传过来的空值判断
我有四个这样的输入值
action到处理的php页面
有没有什么方法能够合理的让php页面的sql语句判断当那个字段为空时,就不以那个为搜索的条件了
除了穷举,还有什么方法?
$sql="select * from table where ..."
实例:
html
foreach(array_diff($_POST, array('')) as $k=>$v)
$r[] = "$k='$v'";
$sql = "select * from student where ". join(' and ', $r);
<br><font color="#e78608">------解决方案--------------------</font><br>应该是,上面少给一个''<br><br>$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]'"; <div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号