MySQL_Narb Posted June 26, 2012 Share Posted June 26, 2012 SELECT `id`,`title`,`date` FROM `messages` WHERE `opened` = '1' AND `status` = '0' OR `status` = '1' AND ". time() ." - `timestamp` < '7889231' AND `receiver` = '!' OR `receiver` = ? ORDER BY `date` DESC In PHP it would be similar to: if(($t = 1 || $t == 2) && $rank < 3) How can I do something similar with this query? In the beginning of the query, you see that the OR throws it off. Is there a way I can do something similar the way PHP does it where: `status` = '0' OR `status` = '1' So in PHP, it would be: if($status == 0 || $status == 1) && $var == 1 && $var == 2) Sorry if I was bad at explaining what I'm looking for. Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/ Share on other sites More sharing options...
mikosiko Posted June 26, 2012 Share Posted June 26, 2012 So in PHP, it would be: if($status == 0 || $status == 1) && $var == 1 && $var == 2) seems that you did answer yourself..... use brackets in the same way in your sql Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/#findComment-1357044 Share on other sites More sharing options...
The Little Guy Posted June 26, 2012 Share Posted June 26, 2012 parenthesis... not brackets Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/#findComment-1357078 Share on other sites More sharing options...
mikosiko Posted June 26, 2012 Share Posted June 26, 2012 parenthesis... not brackets well.. even when this is not a grammar forum... do you know that PARENTHESES (Plural) or parenthesis (singular) are a TYPE OF BRACKETS? ... specifically they are ROUND BRACKETS, and how you call'em in reality depends on which side of world you are. The OP sure is smart enough to understand what to use, moreover when I did quote his own line of code. FYI Types of Brackets: ( ) ? round brackets, open brackets, close brackets (UK), or parentheses [ ] ? square brackets, closed brackets, or brackets (US) { } ? curly brackets, definite brackets, swirly brackets, curly braces, birdie brackets, Scottish brackets, squirrelly brackets, braces, gullwings, seagull, fancy brackets, or DeLorean Brackets[citation needed] ⟨ ⟩ ? pointy brackets, angle brackets, triangular brackets, diamond brackets, tuples, or chevrons < > ? inequality signs, pointy brackets, or brackets. Sometimes referred to as angle brackets, in such cases as HTML markup. Occasionally known as broken brackets or brokets.[1] ? ?; ? ? ? angular quote brackets, or guillemets ⸤ ⸥; 「 」 ? corner brackets Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/#findComment-1357113 Share on other sites More sharing options...
MySQL_Narb Posted June 26, 2012 Author Share Posted June 26, 2012 Thanks for the reply guys! Edit: I tried: WHERE `opened` = '1' AND (`status` = '0' OR `status` = '1') AND ". time() ." - `timestamp` < '7889231' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1340745722 - `timestamp` < '7889231' ORDER BY `date` DESC' at line 1No conversations in this section. Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/#findComment-1357213 Share on other sites More sharing options...
mikosiko Posted June 26, 2012 Share Posted June 26, 2012 post the whole SQL sentence and a few lines sorrounding it Quote Link to comment https://forums.phpfreaks.com/topic/264791-mysql-query-with-a-lot-of-ands-and-ors/#findComment-1357233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.