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!
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...
<?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
*/
}
?>
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...
Place the code found in the default before the switch starts so it runs before it.
good idea. so the code written to decide which displayType to use is before the switch statement and completely outside of the switch statement all together... i can do that =). thanks feyd!
switch($displayType)
{
case 1:
case 2:
// this executes if $displayType == 1 or $displayType == 2
break
case 3:
// this executes if $displayType == 3
break;
}