Jump to content

question about switch() statement


boo_lolly

Recommended Posts

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...
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.