CHAMAVELI Posted September 15, 2008 Share Posted September 15, 2008 Hey guys im very new to PHP and I wanted to know how to add an action like file.php?action=howtodothis Please don't bag me out and if anyone could give me a website that has all these basic things could you please point me there. Thanks, CHAMAVELI. Quote Link to comment Share on other sites More sharing options...
Floydian Posted September 15, 2008 Share Posted September 15, 2008 Re: How to add actions Get ready for a baggin :P The first thing you should know is the concept of key and value pairs. key => value key => value key => value key => value key => value key => value That is the basic format of an array. PHP arrays use key and value pairs. Columns in a database table are keys to the value stored in that column, and the primary key is a key to the row in that table. Keys have to be unique. You can't have one key called action, and another key called action. The second one must be called something else. action2 or actiona will suffice to make it unique from action. I typically use case, them_id, item_id, id, and so on for keys submitted in a url query string. What's a query string? Anything that comes after the ????? in a URL is a query string. action=blah&foo=yay&bar=huh is an example URL query string. action, foo, and bar are keys. If you submit a URL with that query string, then the GET super global array in PHP will contain the array keys: array( 'action' => 'foo' => 'bar' => ) That's the $_GET array. I.e., $_GET['action'], $_GET['foo'], $_GET['bar']. The values assigned to that array are as follows: array( 'action' => 'blah', 'foo' => 'yay', 'bar' => 'huh' ) And now, the $_GET array looks like this: $_GET['action'] === 'blah'; $_GET['foo'] === 'yay'; $_GET['bar'] === 'huh'; Alrighty, now you can use any of those in a switch. A php switch looks like: switch($_GET['action']) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; default: break; } That switch could easily use the key foo or the key bar. Like so: switch($_GET['foo']) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; default: break; } Now, depending on the value foo was set to, the code in the case that matches that value will be executed. case 'yay': call_this_function(); break; In the case of foo, and the query string I demonstrated before, foo has the value "yay". The case of 'yay' will be matched and "call_this_function()" function will be called, and the switch block will be exited. Bam, there you go. Did that help? Quote Link to comment Share on other sites More sharing options...
Tezza` Posted September 15, 2008 Share Posted September 15, 2008 Re: How to add actions Cant get much more help then that lawl :P Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 15, 2008 Share Posted September 15, 2008 Re: How to add actions Or the basics: if($_GET['action'] == "blah") { //do action... } Quote Link to comment Share on other sites More sharing options...
Floydian Posted September 15, 2008 Share Posted September 15, 2008 Re: How to add actions I prefer to be definitive ;) Imagine how good my Horizons Game Engine is :D Quote Link to comment 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.