Jump to content

default under switch question.


Malkavbug

Recommended Posts

(editing for code clean up, sorry)
After the prior one that I figured out myself last minute it does, however, bring up an entirely different issue.

Here is the code (clipped down) then I will explain more

[code]
switch (@$forum)       /*Open of forum switch*/
{
   case "1":    /*Should be ?forum=general */
     {
        switch (@$view)   /*Open of view switch*/
           {
               case "topics":/*Should be ?forum=1&view=topics*/
                  {
                  echo "viewtopics 1 ";
                  break; /* ends ?= caseblock */
                  }
               case "posts":  /*Should be ?forum=1&view=posts*/
                  {
                  echo "viewposts 1 ";  
                  break; /* ends ?= caseblock */
                  }

                  break; /* ends ?= caseblock */
                  default: echo "1 Default ";
            }/*End of view switch*/
       } /*End of Case 1*/


  case "2": /*Should be ?forum=2 */
      {
          switch (@$view)  /*Open of view switch*/
             {
                case "topics":  /*Should be ?forum=2&view=topics*/
                  {
                   echo "viewtopics 2 ";
                   break; /* ends ?= caseblock */
                   }
                   case "posts":/*Should be ?forum=2&view=posts*/
                   {
                   echo "viewposts 2 ";
                   break; /* ends ?= caseblock */
                   }
                   break; /* ends ?= caseblock */
                   default: echo "2 Default ";
             }         /*End of view switch*/

    }                /*End of Case 2*/



break; /* ends ?= caseblock */
/*By default show the main form page*/
default: include("forumbody.php");



    }
/*End of forum switch*/
[/code]


What is working
forumstest.php = forumbody.php included, nothing else

Not working
forumstest.php?forum=1 responds with "1 Default 2 Default"
forumstest.php?forum=1&view=topics responds with "viewtopics 1 viewtopics 2"

So initially I thought it was some "case" collision problem. However all
forumstest.php?forum=2 requests do not include the forum=1 information. In other words they are working fine.

So what can I look at/do to prevent the second case from throwing stuff in if the first case is met? Why is the second case even doing anything when case "2": /*Should be ?forum=2 */ is not met?

Adding in a die() statement at the end of the case 1 stuff is not an option as there are things further down this script that I need to execute. I know I could call it with an include and add a die statement, but I would rather see if there is an actual way to properly do this, and figure out why it is even acting this way to begin with.

Any help is greatly appreciated.


I apologize for the oddly spaced code. I tried fixing it with an edit but it seems like the code box options on the message board are throwing in tabs spaces
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.