Click to See Complete Forum and Search --> : Using AND and OR in an if statement


evenstar7139
06-23-2006, 06:02 AM
Within the confines of a SINGLE if statement....is it possible for me to do this?

If ($user != 'owner' AND $userType != 'moderator' OR $userLevel != 'admin')
{ do the stuff in here }

In laymans terms that is saying if the person viewing the page is NOT the owner but they are a moderator or admin, display the page, if the person is the owner, display the page no matter what, if the person is not the owner and not a moderator or admin, do not display the page.

If the way I have my OR and AND thingies arranged is not right, what modifications do I need to make?

NogDog
06-23-2006, 10:02 AM
You might be over-thinking this. You could just do:

if ($user == 'owner' or $userType == 'moderator' or $userLevel == 'admin')
{
// display the page
}
else
{
// do not display the page
}

themarty
06-23-2006, 08:33 PM
to be explicit about what belongs together when giving multiple arguments to an if, use these: ( )
In your case:
If ( ($user != 'owner') AND ($userType != 'moderator' OR $userLevel != 'admin') )
Although this won't yield the result you want. NogDog has already given the solution to that though