Eowyne Posted June 26, 2008 Share Posted June 26, 2008 Hi there, I'm not new to PHP, I have been creating a lot of things since a year or 7 ago... but I can't help it to be not able to understand this logic which PHP gives me right now... I have a, in my logic, pretty easy IF statement, Which has 4 conditions: $a = 5; $b = 1930; $c = 1; IF($a <= $c OR $a == 1930 AND $b <= $a OR $b == 1930){ echo "true"; } which should read as: IF(5 <= 1 OR 5 == 1930 AND 1930 <= 5 OR 1930 == 1930){ } right? Well, in my logic, $a is NOT Less or Equal to 5, or $a isn't 1930, AND $b isn't Less or Equal to $a, but $b does equal 1930 So this gives me: False for the first section, and a True (or-section) of the second section, however.. knowing that the statement should be both true for section one AND section two, this should give me FALSE as an outcome... However, PHP says it's true... What am I doing wrong? I'm staring myself blind at the moment.. Thanks in advance, Eowyne Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 26, 2008 Share Posted June 26, 2008 Try changing OR to || and AND to &&, also bear in mind && has higher precedence than || Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 http://us.php.net/manual/en/language.operators.php#language.operators.precedence Quote Link to comment Share on other sites More sharing options...
Eowyne Posted June 26, 2008 Author Share Posted June 26, 2008 Wow.. this was way too easy to solve.............. Thnx rhodesa and Roopurt.. you both gave me the exact hints I needed to solve this utterly question.. it was just a manner of adding two ( and ) 's between both sections... IF(($a <= $c || $a == 1930) && ($b <= $a || $b == 1930)){ This indeed gives me false, which I was hoping for ^^ I will bow my head in shame.. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 7 years programming php and you didn't see your error? Quote Link to comment Share on other sites More sharing options...
Eowyne Posted June 26, 2008 Author Share Posted June 26, 2008 And that is why I bow my head in shame. It was way too easy to be go unnoticed, but as I said in my first post.. I've been staring myself blind upon that code, it seemed pretty logic to me, and it was logic, if you omit the () and you just keep on reading over it.. it happens, but I'm glad I've posted the question here It might have taken me longer to notice the brackets missing... It's like staring at a letter with just one spelling-error, which you know is wrong, but you just don't notice it.. and somebody else reads it and notices it right away... ps.... How do I mark this topic '[sOLVED]'? I can't edit my first post... Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 at the bottom of the last post there is an option to mark as solved Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 <?php $a = 5; $b = 1930; $c = 1; IF($a <= $c OR $a == 1930 AND $b <= $a OR $b == 1930) { echo "true"; } ?> That is your code, that I executed, and it returned true... So, what was your problem? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 I agree, silly little mistakes are often the biggest problem with programming. Things like typo's, forgetting semi-colons, forgetting a parenthesis. Quote Link to comment Share on other sites More sharing options...
Eowyne Posted June 26, 2008 Author Share Posted June 26, 2008 ... That is your code, that I executed, and it returned true... So, what was your problem? It had to return false Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 It had to return false [/quote Copied and pasted, didn't edit anything, and it echoes true. Have someone else test it. You may have your variables being reset somewhere or something, I have no idea, but it is true for me. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 If it returned true then there is obviously a problem. 5 is NOT less than 1, hence why it should return false and hence why returning true is a problem. A regular human can even notice that. Quote Link to comment Share on other sites More sharing options...
Eowyne Posted June 26, 2008 Author Share Posted June 26, 2008 Yeah, it returned true because the statement wás true, but I needed the statement to become false (e.g. 1 > 4 or 4 < 2 and 2 > 9 or 2 == 2 gives me true (2 equals 2), and due to me not placing () around the two sections, this is correct, but I needed it to return false: e.g.: (1 > 4 or 4 < 2) and (2 > 9 or 2 == 2) --> False (section one gives false, section 2 true, false AND true = False) So that's why it didn't work like it had to (ps. I omitted the }else{echo "false";} statement) and the reason Why I want it to become false.. I'm creating a scrolling-info bar, at which the admin should be able to start and stop the info shown at a set date (e.g.: it's 26-06-2008 now, and the admin wants the information to be shown only be shown today, so that's why he starts and stops the info at 26-06-2008.. which makes the info dissapear tomorrow (27-06-2008), when the statement returns false It's all a part of a bigger thing, but it was just a silly, nitwit, mistake Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 Oh wow, please forgive my while my foot is in my mouth. *Jabop needs to learn to read Quote Link to comment Share on other sites More sharing options...
Eowyne Posted June 26, 2008 Author Share Posted June 26, 2008 wehehehe, no problem I'm just glad you all gave me a quick reply ^^ Quote Link to comment 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.