Jump to content
MakeWebGames

How to add actions


CHAMAVELI
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...