Welcome to WebmasterWorld Guest from 54.163.52.98

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Else If command

Can this be done?

     

wruk999

10:27 pm on Mar 24, 2003 (gmt 0)

10+ Year Member



Hi,

I have a system which requires logging on etc etc.

Each user is assigned one of three levels, 0, 1 or 2

Most functions/pages can be viewed by all, some can only be viewed by 1 and some by 2 etc etc.

To work this, and instead of having different pages for different users etc, I have else and if statements on the page:

<?
if ($level == 1) {
?>
Info for Level 1 users
<?
}
?>
<?
if ($level == 2) {
?>
Info for Level 2 users
<?
}
?>

What I now need to be able to do is to have an if statement which can handle level 1 AND 2 users at the same time.

Sort of:
if ($level == 1 OR 2)

Does anybody know how this could be done?

Kindest Regards,
William.

jatar_k

11:15 pm on Mar 24, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I would take a look at switch [php.net]

you can then have drop through cases

switch($level){
case 0:
do stuff;
break;
case 1: //this case will drop through to the next because of the missing break
case 2:
do other stuff;
break;

Birdman

11:17 pm on Mar 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe you use the pipe() character for "OR".

if ($level == 1 2)

jatar_k

11:31 pm on Mar 24, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



is a bitwise operator [php.net]
is a logical operator [php.net]

*always replace "" with real pipe character

andreasfriedrich

12:53 am on Mar 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See How to handle permission levels [webmasterworld.com] in the Bag-O-Tricks for PHP II [webmasterworld.com] for a way to handle permission levels more easily.

Andreas

wruk999

7:32 am on Mar 25, 2003 (gmt 0)

10+ Year Member



Hi All...Thanks for responding.

Birdman,
This seems the most simplest and easiest way to do what I need to do, and it works fine...Thank You

Andreas,
Very good post that you refer to..unfortunately this little bit was only needed at the last minute :(, and I don't have the time to change all the other parts of the systemto use the method you explained. No doubt it will come in very handy one day ;)

Thanks again,

William.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month