gpt4 book ai didi

php - MYSQL WITH LIKE, OR, AND, 给出所有结果

转载 作者:太空宇宙 更新时间:2023-11-03 11:52:27 25 4
gpt4 key购买 nike

我正在努力让这个工作发挥作用。

这是我的代码:

     SELECT a1.*
, t2.`name` AS project_name
, t2.`id` AS project_id
, u2.`fname` AS fname
, u2.`lname` AS lname
, u2.`color` AS color
, u2.`id` AS user_id
, u3.`fname` AS creatorfname
, u3.`lname` AS creatorlname

FROM `activities` AS a1
LEFT JOIN `projects` AS t2 ON a1.`projectid`=t2.`id`
LEFT JOIN `users` AS u2 ON a1.`userid`=u2.`id`
LEFT JOIN `users` AS u3 ON a1.`creatorid`=u3.`id`
LEFT JOIN `organisations` AS o1 ON u2.`orgid`=o1.`id` WHERE
o1.`id`=:orgid AND a1.`active`=1 OR a1.`postarea` LIKE '%newyork%'
OR a1.`streetname` LIKE '%newyork%'
OR a1.`companyname` LIKE '%newyork%'
OR a1.`postarea` LIKE '%newyork%'
OR a1.`orgnumber` LIKE '%newyork%'
OR a1.`postcode` LIKE '%newyork%'
OR a1.`homepage` LIKE '%newyork%'
OR a1.`phone1` LIKE '%newyork%'
OR a1.`phone2` LIKE '%newyork%'
OR a1.`phoneswitch` LIKE '%newyork%'
OR a1.`status` LIKE '%newyork%'
OR a1.`turnovermin` LIKE '%newyork%'
OR a1.`turnovermax` LIKE '%newyork%'
OR a1.`description` LIKE '%newyork%'
OR a1.`comment` LIKE '%newyork%'
OR a1.`email` LIKE '%newyork%' AND a1.`projectid`=:projectid
AND a1.`userid`=:userid AND a1.`date`>=:datefrom AND
a1.`date`<=:dateto ORDER BY a1.`date` DESC

问题是,我根据 OR LIKE 语句得到每个结果。我使用 PDO 类,因此它例如:orgid。它应该考虑所有陈述和标准。我已经尝试 ( ) 围绕 AND...等等,但没有任何结果。

希望得到一些帮助。

最佳答案

您需要了解逻辑括号。

a AND b OR c OR d 表示逻辑污染。括号告诉处理器首先执行哪些操作,而不是对每个操作进行同等排序:

a AND (b OR c) - 如果 A 为真且 B 或 C 也为真则为真

(a AND b) OR c - 如果 A 和 B 为真则为真,或者不管它们如何,如果 C 为真

关于php - MYSQL WITH LIKE, OR, AND, 给出所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34774958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com