如何使用php和mysql执行多个AND运算符和OR运算符?

第一个查询有效并显示正确的结果。当我添加额外的 AND 条件时,我收到“试图获取非对象的属性”错误。


我可以在一个 OR 和另一个条件下成功执行。


这是回显的查询:


SELECT * FROM scores 

WHERE (sortDate <= 20190629 AND sport = football) 

       AND (homeID = 4 OR awayID = 4) 

ORDER BY gameDate DESC

我确定变量正在通过。


这个工作正常:


$sql = "SELECT * FROM scores 

WHERE sortDate <= $today

AND (homeID = $teamID OR awayID = $teamID)

ORDER BY gameDate DESC";

这个给出了一个错误(添加了 AND):


$sql = "SELECT * FROM scores 

WHERE (sortDate <= $today AND sport = $sportID)

AND (homeID = $teamID OR awayID = $teamID)

ORDER BY gameDate DESC";


Cats萌萌
浏览 191回答 1
1回答

狐的传说

尝试这个$sql = "SELECT * FROM scores&nbsp;WHERE (sortDate <= $today AND sport = '$sportID')AND (homeID = $teamID OR awayID = $teamID)ORDER BY gameDate DESC";或者$sql = "SELECT * FROM scores&nbsp;WHERE (sortDate <= $today) AND (sport = $sportID)AND (homeID = $teamID OR awayID = $teamID)ORDER BY gameDate DESC";
打开App,查看更多内容
随时随地看视频慕课网APP