SkyRanger Posted September 6, 2007 Share Posted September 6, 2007 I am not sure if it too early in the morning or what, but I am having a major brain fart..lol. This is what I need, not sure if switch would work better though: $allowaccess = ""; if($access == "9") { $allowaccess = " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br> <?=$officelink; ?> <br>"; } elseif($access == "8") { $allowaccess = " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br> <?=$officelink; ?> <br>"; } } elseif($access == "7") { $allowaccess = " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br> <?=$officelink; ?> <br>"; } } elseif($access == "6") { $allowaccess = " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br> <?=$officelink; ?> <br>"; } ..etc echo $allowaccess; Yeah, yeah i know <?= is not proper but it is old code. Or is there an easier way than this? like if($access >="4") { Quote Link to comment https://forums.phpfreaks.com/topic/68207-solved-elseif-statement/ Share on other sites More sharing options...
micah1701 Posted September 6, 2007 Share Posted September 6, 2007 did you try your own suggestion? it should work Quote Link to comment https://forums.phpfreaks.com/topic/68207-solved-elseif-statement/#findComment-342900 Share on other sites More sharing options...
wildteen88 Posted September 6, 2007 Share Posted September 6, 2007 If you only want access numbers 6 through to 9 to show a link to office.php just use a simple if statement: // if access greater than or equal to 6 and is less than or equal to 9 // echo link to office.php if($access >= 6 && $access <= 9) { echo " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/68207-solved-elseif-statement/#findComment-343041 Share on other sites More sharing options...
skateme Posted September 6, 2007 Share Posted September 6, 2007 try using switch switch(variable) { case "1"; execute commands; break; case "1"; execute commands; break; it goes something like that. go to php.net and search for switch Quote Link to comment https://forums.phpfreaks.com/topic/68207-solved-elseif-statement/#findComment-343051 Share on other sites More sharing options...
SkyRanger Posted September 6, 2007 Author Share Posted September 6, 2007 If you only want access numbers 6 through to 9 to show a link to office.php just use a simple if statement: // if access greater than or equal to 6 and is less than or equal to 9 // echo link to office.php if($access >= 6 && $access <= 9) { echo " <a class=\"sidelink\" href=\"../office.php\">The Office</a><br>"; } Thanks wildteen88, that worked exactly as I needed it. I had that earlier but forgot to put && only had 1 & and couldn't figure out the problem..lol Quote Link to comment https://forums.phpfreaks.com/topic/68207-solved-elseif-statement/#findComment-343066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.