Aureole Posted October 14, 2007 Share Posted October 14, 2007 This is an overly simplified example of what I am actually doing but you get the idea. I bet there's a better way to do this... The code doesn't really make sense but you get the idea... I should also probably be checking that there's an act before showing a do or an action like if(isset($_GET['act']) && $_GET['act'] == 'one' && $_GET['do'] == 'something') { ... But that is besides the point, what is the best way of doing this? Should I just use another switch statement for each one or would that not work? Any input is appreciated. <?php switch($_GET['act']) { case 'one'; one(); break; case 'two'; two(); break; default: one(); break; } function one() { if($_GET['do'] == 'something') { echo('Something.'); } elseif($_GET['do'] == 'somethingelse') { if($_GET['action'] == 'dothis') { echo('Do this.'); } elseif($_GET['action'] == 'dothat') { echo('Do that.'); } else { echo('Something...'); } } } function two() { // ... } ?> I already searched Google and couldn't find anything, just so you know... Quote Link to comment https://forums.phpfreaks.com/topic/73170-best-way-to-handle-multiple-_gets/ Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Probably easiest to setup a seperate switch to deal with every $_GET var. eg; <?php if (isset($_GET['action'])) { switch ($_GET['action']) { // run functions based on action. } } if (isset($_GET['view'])) { switch ($_GET['view']) { // run functions based on view. } } // etc etc ?> Quote Link to comment https://forums.phpfreaks.com/topic/73170-best-way-to-handle-multiple-_gets/#findComment-369096 Share on other sites More sharing options...
marcus Posted October 14, 2007 Share Posted October 14, 2007 You could also do include files if you don't want it to be all on one page. Quote Link to comment https://forums.phpfreaks.com/topic/73170-best-way-to-handle-multiple-_gets/#findComment-369103 Share on other sites More sharing options...
Aureole Posted October 14, 2007 Author Share Posted October 14, 2007 I tried that then but then when I use functions from my class like $class->function(); within the include I get an error, or maybe I just did it wrong... I don't know I posted in OOP anyway. But at first I thought it was because it was within an include, then I tried it in the file itself and I still got the error. Including isn't a bad solution anyway but it can get a little messy... Quote Link to comment https://forums.phpfreaks.com/topic/73170-best-way-to-handle-multiple-_gets/#findComment-369110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.