我拉我的頭髮在這裏試圖讓這個工作。MYSQL像,或者和,給出所有結果
這是我的代碼:
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
的問題是,我得到一個基於或類似語句的每個結果。 因此我使用PDO類,例如:orgid。它應該考慮所有的陳述和標準。我嘗試過()和...等,但沒有任何結果。
希望得到一些幫助。
'WHERE O1 \'ID \'=:。ORGID AND(OR值一束)和A 1 \'專案編號\'=:專案編號和A 1 \'的userid \'=:用戶標識和A1 \。 'date \'> =:datefrom AND a1 \'date \'<=:dateto' – MonkeyZeus
您需要了解邏輯括號。 – Utkanos
你必須告訴我們你想要的結果。你的陳述對我來說很奇怪,太複雜了。你爲什麼要問「紐約」10次? – etalon11