Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Switch commands, using 2 $do

    I use switch commands like the following.

    Code:
    case 'onlineusers':
    		onlineusers();
    		break;
    and the old setup is like this.

    Code:
    elseif ($do[0] == "delete") { delete($do[1],$do[2]);}

    But how do you use $do[1],$do[2] in a switch command? My best guesses are one of the following.

    case 'onlineusers':
    onlineusers($do[1]);
    onlineusers($do[2]);
    break;

    or

    case 'onlineusers':
    onlineusers($do[1],$do[2]);
    break;

    is either correct?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This depends on what the function onlineusers does, and what $do represents. The switch is really just a shorter method of splitting if/elseif/else syntax - I don't embed more than 2 elseif's before I switch to a switch statement. From what you have, I gather you do something like the following:
    PHP Code:
    switch $do[0]
    {
        case 
    'delete':
            
    delete($do[1], $do[2]);
            break;
        case 
    'update':
            
    update($do[1], $do[2]);
            break;
         case 
    'onlineusers':
            
    onlineusers($do[1], $do[2]);
            break;
         default:
            throw new 
    Exception('Cannot process $do[0]');

    I don't know if this is exactly what you have or not, and all I can say about you're two suggestions is that either may work, or neither may work. Without the function onlineusers and knowing what the $do array contains, I can't tell you if this is right or how to make it right.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    masterofollies (07-26-2008)

  • #3
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    masterofollies, have you tried to do your two examples that you give? Why haven't you just tried it yet? It would be easier for us to help you if you are running into a specific problem and give us the error message you receive or something. Let us know if there's something more specific we can help with!

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ah ha, Fou wins again. This seems to have done the trick.

    Code:
     case 'delete':
                   delete($do[1], $do[2]);
            break;
    $do[1] is the ID of the thread I am deleting and $do[2] is the forum in which the thread is being deleted from.

    Thanks again!

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I can't really take any credit though, you found the solution yourself. I just mentioned that either may work or neither may work - its all dependent on the function and the values
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yeah but you helped on all my other problems. You deserve it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •