PHP
  Home arrow PHP arrow Page 4 - Building a Quick and Easy Tag Board
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building a Quick and Easy Tag Board
By: Haiden Taylor
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 120
    2004-11-03


    Table of Contents:
  • Building a Quick and Easy Tag Board
  • Did Anyone Say MySQL?
  • Our Tag Board Script
  • What Makes Our Tag Board Tick?
  • Our Tag Board Functions!
  • Retrieval and Sorting of Tags
  • Results
  • doBoard() Function
  • doInsert() Function
  • Ensuring Data Submitted Does Not Fail
  • Inserting into the Tag Board

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Quick and Easy Tag Board - What Makes Our Tag Board Tick?
    ( Page 4 of 11 )

    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
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek