在一个页面中,它应显示下拉菜单中包含以下所选月份的记录,并在?month = March
中设置因此查询将执行此操作
$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) . "' AND finished='0' ORDER BY date ASC";
但它显示完成列中值为2的记录,我不希望查询包含此内容。
我试过
$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) . "' AND finished='0' OR finished = '1' OR finished = '3' ORDER BY date ASC";
但它显示了不同月份的记录。
所以基本上我希望记录排除记录中 2 的记录,这些记录将不会显示在页面中。
答案 0 :(得分:0)
您的第一个查询应该执行您想要的操作。不应返回finished = '2'
行。
忽略您的第二个查询中可能应该修复的错误:
$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) .
"' AND (finished='0' OR finished = '1' OR finished = '3') ORDER BY date ASC";
区别在于OR子句的括号,因为AND的绑定比OR更强。
您还可以使用IN
更简洁地获得相同的结果:
$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) .
"' AND finished IN ('0', '1', '3') ORDER BY date ASC";
答案 1 :(得分:0)
AND finished='0' OR finished = '1' OR finished = '3'
到
AND finished != 2
或
AND (finished = 0 OR finished = 1 OR finished = 3)