PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Mar 21, 2005 10:05 pm
Hi,
elseif not working right ..
Code: Select all
if($_SESSION['user_level'] == 5) {
echo "this";
}else if($_SESSION['user_level'] == 4) {
echo "or this";
}else if($_SESSION['user_level'] == 3) {
echo "Or maybe this";
}else{
echo "that";
Is that correct the if .. works .. and the first else if .. but the next else if has srange issues ..
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 21, 2005 10:12 pm
for something like this, use a switch.
elseif .. else if is different functionality, although very similar, has slightly differing logic handling sometimes..
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Mar 21, 2005 10:43 pm
Hi,
Is it something like the following:
Code: Select all
switch(user_level) {
case 1: ($_SESSION['user_level'] == 5)
echo " | <a href=\"#\" onMouseOver=\"showmenu(event,linkset[1])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
case 2: ($_SESSION['user_level'] == 4)
echo " | <a class=\"two\" href=\"#\" onMouseOver=\"showmenu(event,linkset[2])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
case 3: ($_SESSION['user_level'] == 3)
echo " | <a class=\"two\" href=\"#\" onMouseOver=\"showmenu(event,linkset[3])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
default:
echo "";
}
I get an error ot the first echo ..?
Thanks ..
Last edited by
Jim_Bo on Mon Mar 21, 2005 11:20 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 21, 2005 11:08 pm
you pass nothing to switch(), your breaks don't have semicolons, your default is errored.
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Mar 21, 2005 11:24 pm
Hi,
Is this correct?
Code: Select all
<?php
switch (user_level) {
case ($_SESSION['user_level'] == 5):
echo " | <a href=\"#\" onMouseOver=\"showmenu(event,linkset[1])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
case ($_SESSION['user_level'] == 4):
echo " | <a href=\"#\" onMouseOver=\"showmenu(event,linkset[2])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
case ($_SESSION['user_level'] == 3):
echo " | <a href=\"#\" onMouseOver=\"showmenu(event,linkset[3])\" onMouseOut=\"delayhidemenu()\">ADMIN</a>";
break;
default:
echo " ";
}
?>
Thanks ..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 21, 2005 11:33 pm
you're not asking it to check the session data.
Code: Select all
switch($_SESSIONї'user_level'])
{
case 5:
// do a user level 5 thing
break;
default:
// do an uncaptured thing
break;
}
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Mar 21, 2005 11:42 pm
Hi,
Thanks for that .. Works a treat ..
It seems to work with:
Is that posible and just bad design leavin out the session?
Thanks ..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 21, 2005 11:46 pm
it only works to a minor degree. Your code is exploiting the handling of unknown constant strings, and the case comparison system. If you had error_reporting cranked to all, you'd very likely get a notice about user_level being an unknown constant, assuming 'user_level'
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Tue Mar 22, 2005 12:38 am
Hi feyd,
Great .. Thanks for the explaination .. You are a very knowledgeable person .. Your help is very much appreciated!
Jimbo