繁体   English   中英

检查WHERE子句中的条件

[英]Check conditions in WHERE clause

我的选择查询有问题。 我有4个条件检查此查询。

$subject // This condition is always true that mean it has a value when executing the query
$option // This condition is also true that mean it has a value when executing the query
$district // Maybe this is true or not
$city // Maybe this is true or not

现在,我需要使用这4个条件进行选择查询。

我可以知道有什么方法可以将这4个条件添加到我的WHERE子句中,然后检查是否为真,然后根据查询满足的条件返回记录。

希望有人能帮助我。

谢谢。

当然-将它们与ANDOR连接

SELECT * FROM .. WHERE subject=? AND ...

希望您可以避免输入(如果使用准备好的语句,PDO会为您完成此工作)

这个怎么样?

WHERE   $subject = 1 AND
        $option = 1 AND
        $district IN (0,1) AND
        $city IN (0,1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM