2015-10-29 82 views
0

您好我有一個與發佈= 3的值錯誤的查詢結果中的mysqli

但此查詢打印!(它不應該)

SELECT * FROM article WHERE publish BETWEEN 0 AND 2 AND feature = '1' 
AND sid = '3' OR sid = '4' OR sid = '5' OR sid = '6' OR sid = '7' 
OR sid = '8' OR sid = '9' OR sid = '10' AND created BETWEEN 0 
AND 1446078164 ORDER BY id DESC LIMIT 0, 6     

什麼是我的錯申請?

更多信息:

的地方,主要有4集羣: WHERE發佈介於0和2

AND feature = '1' 

AND sid = '3' OR sid = '4' OR sid = '5' OR sid = '6' OR sid = '7' 
OR sid = '8' OR sid = '9' OR sid = '10' 

AND created BETWEEN 0 AND 1446078164 
+0

太多怪異的條件使得它難以閱讀和理解 – Marcin

+0

你真的應該用括號跟蹤發生了什麼事情。 –

回答

2

你需要括號,可能in。我猜你想要的邏輯是:

SELECT * 
FROM article 
WHERE publish BETWEEN 0 AND 2 AND 
     feature = '1' AND 
     sid IN ('3', '4', '5', '6', '7' , '8', '9', '10') AND 
     created BETWEEN 0 AND 1446078164 
ORDER BY id DESC 
LIMIT 0, 6;