HomePHP Page 7 - Building a Quick and Easy Tag Board
Results - 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.
First off we have checked whether the MySQL query has returned 1 or more rows. We do this because the query may be executed successfully, but there may be no tags stored in the database, so we need to let the user know that no tags have been submitted yet.
If one or more results were returned by the database, we will look through them, displaying them one at a time using a while loop. Since we used the mysql_fetch_assoc() function, we will be accessing the specific fields by using the following syntax, $array_name[‘field_name’] . Therefore in our script we would use the following to display the field name minus the slashes echo stripslashes($arrow[‘tag_entry’]);
Note: The reason we remove the slashes is because in the doInsert() function we add slashes to the posted data to improve database integrity.
You may also notice a function in around the code to display to the tag entry which is nl2br(). This function will change \n to <br /> which will improve overall formatting. More information is available at www.php.net/nl2br
In the instance where no rows were returned by the MySQL query, we would need to let the user know that there was nothing to display. We have achieved this with the “else” section of our if statement. If our MySQL query returned less than 1 row (e.g. no rows in the database), then we display a message to the user informing them of the situation.