Pandolfo Posted February 5, 2008 Share Posted February 5, 2008 Hey everyone, I have a bit of code i'm working on which, despite trying everything which normally works, doesn't behave the way its written to. The whole thing works fine in my local environment, but when i upload it to the server it dies.I'm concatenating three variables, each one digit in length, to create a three digit result code. I know the code is created correctly, resulting in just three digits. This code is fed to the switch statement which then displays a block of html specific to the code. Simple right? The problem is that the switch statement doesn't seem to like the concatenated variable. Instead of processing the argument and displaying the code, it heads straight for the default statement. If i hard-code the variable to any of the possible codes in the switch statement it works just fine. Is it a problem with the switch statement or the concatenation? Any ideas would be a great help. Thanks! $decadecode=$fired.$divorced.$decadenumber; switch ($decadecode): case 001: case 002: case 003: echo $marriedemployed; break; case 004: echo $marriedemployedfinal; break; case 101: case 102: case 103: echo $firedmarried; break; case 104: echo $firedmarriedfinal; break; case 011: case 012: case 013: echo $divorcedemployed; break; case 014: echo $divorcedemployedfinal; break; case 111: case 112: case 113: echo $fireddivorced; break; case 114: echo $fireddivorcedfinal; break; default : echo "Your account has been locked as a safety measure. Please contact the site administrator as soon as possible. System code: $decadecode"; endswitch; Quote Link to comment https://forums.phpfreaks.com/topic/89568-solved-the-switch-statement/ Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 enclose all your cases in quotes - when you concatenate the numbers you turn them into a string. You are checking for the existence of numbers, and comparing them to strings. Quote Link to comment https://forums.phpfreaks.com/topic/89568-solved-the-switch-statement/#findComment-458855 Share on other sites More sharing options...
sasa Posted February 5, 2008 Share Posted February 5, 2008 try $decadecode = $fired * 100 + $divorced * 10 + $decadenumber; Quote Link to comment https://forums.phpfreaks.com/topic/89568-solved-the-switch-statement/#findComment-458856 Share on other sites More sharing options...
Pandolfo Posted February 5, 2008 Author Share Posted February 5, 2008 Outstanding! Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/89568-solved-the-switch-statement/#findComment-458861 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.