boo_lolly Posted January 16, 2007 Share Posted January 16, 2007 i have a switch statement that each case will display the products of an inventory in a different manner. as you can see the default; in the switch statement is where the variable will go through a few if statements and dictate what case; it should be (how the products should be displayed). i'm not sure if this will work the way i want it to, as in, i'm not sure switch statements work this way. but after a few if statements, the code will come to a conclusion and decide what the case should be, and it sets that variable to the correct value. i want the switch statement to emmediately change it to that case. does the page need to be reloaded in order for it to work correctly? does the default need to be written BEFORE the rest of the cases? maybe take out the 'break' command? here's my code...[code]<?php switch($displayType){ case 1; /*display items in this way*/ break; case 2; /*display items in a different way*/ break; case 3; /*display items in another way*/ break; default; /* *some if statements go here *and set $displayType to *1, 2, or 3... etc */ }?>[/code]i'm not getting any errors or anything.. that's just there to help you understand my question. if switch() statements can do that without reloading the page... Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 16, 2007 Share Posted January 16, 2007 I'm really not understanding your question, but switch statements have nothing to do with "reloading the page". They are simply a way in which to have mutiple possible outcomes for a given value. No different than if you used a bunch of elseif's Quote Link to comment Share on other sites More sharing options...
Barand Posted January 16, 2007 Share Posted January 16, 2007 in which case I'd do this[code]<?php/* *some if statements go here *and set $displayType to *1, 2, or 3... etc*/ switch($displayType){ case 1; /*display items in this way*/ break; case 2; /*display items in a different way*/ break; case 3; /*display items in another way*/ break;}?>[/code] Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 16, 2007 Author Share Posted January 16, 2007 thanks guys. that's exactly what i'm going to end up doin barand Quote Link to comment 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.