STaRDoGG Posted July 23, 2009 Share Posted July 23, 2009 Hey all, PHP isn't a particular strength of mine syntax-wise; can anyone spot what's wrong with this line? if ($GSFilterEx == false || $GSFilterEx == true && !GS_Exclusions($GSName) == "match") $GSFilterEX is a checkbox that returns either 0 or 1 (false or true). GS_Exclusions is a function that either returns "match" or "no match" depending on of a particular persons name was found in an array in that function. I've already tested the function and it works ok. What I want it to do is: There is some code to run following that line, that I only want to execute IF the checkbox is either unchecked, OR it is check AND is not a match. So essentially, the code following that line should always execute unless there is a match with the user's name. For some reason though, the code following that line is not being executed, even though I have the box checked, and it's not a match. Anyone have any ideas? Thanks in advance Quote Link to comment Share on other sites More sharing options...
9three Posted July 23, 2009 Share Posted July 23, 2009 Try this: if ($GSFilterEx == false || ($GSFilterEx == true && !GS_Exclusions($GSName) == "match")) If that doesn't work then there is something wrong with your function. Quote Link to comment Share on other sites More sharing options...
stickynote427 Posted July 23, 2009 Share Posted July 23, 2009 Perhaps change !GS_Exclusions($GSName) == "match" to GS_Exclusions($GSName) != "match"? It looks to me like that's what could be causing the error, but maybe how you did it is perfectly acceptable as well. I just personally have never seen it done that way, so that's what I'm suggesting; I apologize if that does not solve your problem. Quote Link to comment Share on other sites More sharing options...
STaRDoGG Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks guys, Stickynote's solution did the trick Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 24, 2009 Share Posted July 24, 2009 You had better also implement 9three's suggestion as well or that test will not work as you expect. The first two tests would cancel themselves out (because one would always be true)and only the last test would determine if the output is true or not. Unless you group conditions together they are interpreted from left to right including the AND/OR's. This is what you have: Test1 OR Test2 AND Test3 In processing the code each test is checked individually Then the AND/OR are used - again from left to right. So, it will first check if Test1 OR Test2 are true. Since they are opposites of each other that test will always return true. Then the next step it to compare the result of the Test1/test2 comparison with Test3. So you end up with TRUE AND Test3 So, the result of your test will end up being the result of Test3. you need to group the conditions as 9three suggested Quote Link to comment Share on other sites More sharing options...
STaRDoGG Posted July 24, 2009 Author Share Posted July 24, 2009 Aahh gotcha. Funny thing was I originally had both of them together, then while testing later it seems to behave the same, so I took out what just appeared ot be 'extra formatting'. I put it back again. Thanks all 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.