Home arrow PHP arrow Page 4 - Building a Quick and Easy Tag Board

What Makes Our Tag Board Tick? - PHP

Tag boards enable users to leave a short message on your site without having to go through the trouble of registering. From a development point of view, they are actually rather simple to develop. In this article we will create a quick and easy tag board for any web site. We will be taking advantage of the php and MySQL technologies.

TABLE OF CONTENTS:
  1. Building a Quick and Easy Tag Board
  2. Did Anyone Say MySQL?
  3. Our Tag Board Script
  4. What Makes Our Tag Board Tick?
  5. Our Tag Board Functions!
  6. Retrieval and Sorting of Tags
  7. Results
  8. doBoard() Function
  9. doInsert() Function
  10. Ensuring Data Submitted Does Not Fail
  11. Inserting into the Tag Board
By: Haiden Taylor
Rating: starstarstarstarstar / 120
November 03, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

First off let's look at our defined constants:

define('HOST', 'localhost');
define('USER', 'mysql_username');
define('PASS', 'mysql_pass);
define('DB', 'mysql_db');

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) {
case "Board":
doBoard();
break;
case "Tags":
doTags();
break;
case "Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__url']);
break;
default:
doBoard();
}

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.

"The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for."

Now our code:

switch ($do) {
case "Board":
doBoard();
break;
case "Tags":
doTags();
break;
case "Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__url']);
break;
default:
doBoard();
}

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.



 
 
>>> More PHP Articles          >>> More By Haiden Taylor
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: