为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
Cats萌萌 2021-09-18 10:56:41
第一个查询有效并显示正确的结果。当我添加额外的 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 <= $todayAND (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";
查看完整描述

1 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

尝试这个


$sql = "SELECT * FROM scores 

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

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

ORDER BY gameDate DESC";

或者


$sql = "SELECT * FROM scores 

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

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

ORDER BY gameDate DESC";


查看完整回答
反对 回复 2021-09-18
  • 1 回答
  • 0 关注
  • 190 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信