【发布时间】:2013-06-13 12:40:37
【问题描述】:
正如我在标题中解释的那样,我想在我的 php 页面上创建一个 sql 查询,以在变量存在的函数中返回特定的结果。 我的页面顶部有一个表单,其中包含一些输入(日期、姓名等),当我单击时,我会刷新页面并显示正确的结果。
目前我的语法是:
if (isset($_POST['dated']) && $_POST['dated'] != null){
$doleances = $bdd->prepare('SELECT * FROM doleance WHERE Priorite < 5 AND Date >= ? ORDER BY ID DESC');
$doleances->execute(array($newDate));
}
else if (isset($_POST['dated']) && $_POST['dated'] != null && isset($_POST['datef']) && $_POST['datef'] != null){
$doleances = $bdd->prepare('SELECT * FROM doleance WHERE Priorite < 5 AND Date BETWEEN ? AND ? ORDER BY ID DESC');
$doleances->execute(array($newDate, $newDate2));
}
else if{...}
else if{...}
...
但我认为有更好的方法来做到这一点...... 提前致谢
【问题讨论】:
-
似乎
else if分支的代码无法访问。 -
看看这里描述的方法:stackoverflow.com/questions/17051539/…
-
isset()可以接受比 1 更多的参数进行检查