Jump to content

Spot the problem


STaRDoGG

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.