HomePHP Page 2 - Building a Quick and Easy Tag Board
Did Anyone Say MySQL? - 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.
As mentioned briefly on the previous page, our tag board will take advantage of a MySQL database to store the information (tags). The MySQL table I will be using for this is below:
CREATE TABLE `tagboard` ( `tagId` int(11) NOT NULL auto_increment, `tag_name` varchar(55) NOT NULL default '', `tag_url` varchar(255) NOT NULL default '', `tag_entry` text NOT NULL, `tag_date` int(11) NOT NULL default '0', PRIMARY KEY (`tagId`) ) TYPE=MyISAM AUTO_INCREMENT=1 ;
You will need to add this table to a MySQL database; you can do this through the MySQL console or through a program like phpMyAdmin.
Our above table will store all our data (tags) indexed by a tagId, which is assigned to each tag by MySQL; this is commonly referred to as an “auto_increment” index. The reason I have included this column is because it is my preferred method of indexing, and it enables us to easily identify the tags if we were to create some admin functions (e.g. delete-tags.php?tagId=123).
The next field in our table is “tag_name” which will store the users name, this is a varchar as most Internet users generally possess an Internet-only secret identity and generally write their “name” using a multitude of strange characters. Which is fine by us. The only restriction we have is the number of characters in that name, in our case 55; we administer this simply by setting maxlength=”55” in our HTML input tag (e.g. <input type="text" name="__name" size="20" maxlength="55" class="inputform">).
Following this we have “tag_url” which will store the URL of the user, if applicable, meaning this is not a required field. It is a varchar also and is limited to 255 characters by maxlength=”255” again.
Now we are storing the body of our tag in the “tag_entry” field. This field is of the text type; this is limited to 400 characters by our HTML input tags once again.
The next field is where we are storing our date, “tag_date” which is of the int type, and 11 characters long. Some of you may be wondering why I have chosen to use “int” instead if “date” or “date-time”. The reason I have done this is because we are using the php Unix Epoch style of timestamp (time()) rather than the a MySQL timestamp.