lnenad Posted January 3, 2010 Share Posted January 3, 2010 ($res['cat']!="Nothing" || $res['cat']!="Something"){ do some code } That for some reason is not working and the code gets executed even though $res['cat']!="Something" . When i try the conditions separately it doesn't. I don't understand what's wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/187045-multiple-if-conditions-not-working/ Share on other sites More sharing options...
premiso Posted January 3, 2010 Share Posted January 3, 2010 You need to provide some more information, like what is $res['cat']? As if it is not Something or Nothing it will execute. Perhaps you wanted an AND instead of an OR? Quote Link to comment https://forums.phpfreaks.com/topic/187045-multiple-if-conditions-not-working/#findComment-987761 Share on other sites More sharing options...
lnenad Posted January 3, 2010 Author Share Posted January 3, 2010 You need to provide some more information, like what is $res['cat']? As if it is not Something or Nothing it will execute. Perhaps you wanted an AND instead of an OR? I need OR . $res is a mysql return array ['cat'] is a column. It represents some categories, 5 of them, and some (3) have additional info to be displayed, 2 of them don't so i don't want to display that additional information when the categories selected aren't those 3. If it's NOT EQUAL 4 OR 5 display the info, otherwise don't display it, hence the IF ($res['cat']!="Nothing" || $res['cat']!="Something"){ do some code } Quote Link to comment https://forums.phpfreaks.com/topic/187045-multiple-if-conditions-not-working/#findComment-987766 Share on other sites More sharing options...
premiso Posted January 3, 2010 Share Posted January 3, 2010 Give and a try. Because if it is equal to anything but 4 or 5 you want to display the information: if ($res['cat'] != "Nothing" && $res['cat'] != "Something") { That is how you would display not equal to "4 or 5" just because there is an or in that statement does not mean that is what you want to use. Give it a try. The and statement, both those conditions have to be true to execute. So the cat cannot equal nothing OR something. If it does it will not execute. Your OR statement was always executing because if $res['cat'] was not "something" or not "nothing" then it would execute it. Hope that makes sense, kind of a hard thing to explain, but basically that OR statement you had originally would execute no matter what, because $res['cat'] cannot be both of those. Quote Link to comment https://forums.phpfreaks.com/topic/187045-multiple-if-conditions-not-working/#findComment-987770 Share on other sites More sharing options...
lnenad Posted January 3, 2010 Author Share Posted January 3, 2010 Nice, works like a charm ! My logic is faulty Thanks a lot mate Quote Link to comment https://forums.phpfreaks.com/topic/187045-multiple-if-conditions-not-working/#findComment-987771 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.