/    Sign up×
Community /Pin to ProfileBookmark

Using AND and OR in an if statement

Within the confines of a SINGLE if statement….is it possible for me to do this?

[code=php]If ($user != ‘owner’ AND $userType != ‘moderator’ OR $userLevel != ‘admin’)
{ do the stuff in here }[/code]

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?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 23.2006 — You might be over-thinking this. You could just do:
[code=php]
if ($user == 'owner' or $userType == 'moderator' or $userLevel == 'admin')
{
// display the page
}
else
{
// do not display the page
}
[/code]
Copy linkTweet thisAlerts:
@themartyJun 24.2006 — to be explicit about what belongs together when giving multiple arguments to an if, use these: [b]( )[/b]

In your case:
[code=php]If ( ($user != 'owner') AND ($userType != 'moderator' OR $userLevel != 'admin') )[/code]
Although this won't yield the result you want. NogDog has already given the solution to that though
×

Success!

Help @evenstar7139 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...