...

View Full Version : Switch commands, using 2 $do



masterofollies
07-26-2008, 02:55 PM
I use switch commands like the following.


case 'onlineusers':
onlineusers();
break;

and the old setup is like this.


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?

Fou-Lu
07-26-2008, 07:25 PM
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:


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.

JohnDubya
07-26-2008, 07:48 PM
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! :thumbsup:

masterofollies
07-26-2008, 10:21 PM
Ah ha, Fou wins again. This seems to have done the trick.


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!

Fou-Lu
07-27-2008, 01:21 AM
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 ;)

masterofollies
07-27-2008, 02:56 AM
Yeah but you helped on all my other problems. You deserve it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum