First off let's look at our defined constants: define('HOST', 'localhost'); These constants represent the MySQL server connection variables and the MySQL database where our table can be found. Once they have been defined, they cannot be changed. For more information on these, please see http://www.php.net/manual/en/language.constants.php Note: You need to change the HOST, USER, PASS, DB constants to match your MySQL host, username, password and database. Next in the code are our three functions, which we will go into detail on separately. I wish to skip to the comparison operator and our switch statement. The code I am referring to is below: $do = (isset($_GET['do']) ? $_GET['do'] : FALSE); switch ($do) { The comparison operator is the first line of code in the snippet above. What this code is doing is checking whether the $do variable is set in the URL. This is achieved by first checking whether if the variable $do has been carried through the URL: isset($_GET[‘do’]) Our ternary operator allows us to choose what we do with our variable depending on what our isset() function returns. To make it simple I will try to establish how the operator will work: $do = (isset($_GET['do']) ? TRUE : FALSE); So if our function returns true, we will execute the code in the “TRUE” part of our operator; if the isset function returns false, we will execute the code in the “FALSE” part of the function. In our case if the isset($_GET[‘do’] function returns true, we want to set the variable to the value contained in the URL, example: Board.php?do=Insert We would want $do to equal “Insert”. In the instance that no variables are passed through the URL, we want our $do variable to be set to false. We achieve this by using the following code: $do = (isset($_GET['do']) ? $_GET['do'] : FALSE); Switch Statement Now let's have a look at our switch statement. Below is a quote from www.php.net/switch, which I believe describes perfectly a switch statement.
Now our code: switch ($do) { I won't go into too much detail with switch statements; basically, if in our URL we have board.php?do=Tags, our script will run the dotages() function, or if there is no variable passed through the URL and our comparison operator sets $do to false, the default function will be run, in this case “doBoard()”. This is reasonably easy to grasp and getting too far into the inner workings of switch statements, which is out of the scope of this article, so we will move on to our functions.
blog comments powered by Disqus |
|
|
|
|
|
|
|