As the web grows, more and more sites are beginning to take advantage of PHP. This article shows just one of the many solutions PHP offers -- making your own dynamic website.
A dynamic website, for those of you who don't know, is a website that is run through a database. The advantages over a static website is that both updating and editing layouts is made a lot simpler.
Before you do any coding, you need to set up your table inside your MySQL database. Setting up a table involves creating and naming the table, but also naming the fields (columns) for your table, as well as assigning properties or rules for those columns. For this article I've provided the SQL to create your database below:
CREATE TABLE `content` ( `Name` varchar(100) NOT NULL default '', `Author` varchar(60) NOT NULL default '', `Description` text NOT NULL, `Body` text NOT NULL, `ID` int(11) NOT NULL auto_increment, PRIMARY KEY (`ID`) ) TYPE=MyISAM AUTO_INCREMENT=14 ;
After opening phpMyAdmin, select the database given to you by your host, or one you setup in your host's control panel, on the left menu. When you come onto the next page, click on the "SQL" tab near the top of the page. Now you have two options. You can just copy the text that I gave you into the large text box, or you can browse to the SQL file saved on your computer. After loading the text or the file submit the form and your database should be created.
Below you will find a table explaining some of the settings and options used in the SQL above. It is important that you understand these features.
|Varchar(100)||We used this datatype for the Name and Author field. Although we could have just made them normal Text datatypes, the advantage now is that we can run indexes, which speed up searches and make them less resource intensive. The number provided, in this example "100" is the maximum length of the field. Make this as long as you need it but not longer than you need. In this case we assume that there will never be a title over 100 characters in length. The maximum amount of characters that a varchar field can have is 255.|
|Text||We used this datatype for Description and Body. In this case, Text won over Varchar because of the maximum character length. Obviously the Body text and Description is going to be longer than both the Name and Author.|
|Int(11)||This datatype was used for the ID field. Int is used for rows that will contain whole numbers.|
|auto_increment||This was assigned to ID as an "extra". Auto_increment basically means that when a row is set at one number, increase it by one for the next row. This makes sure that the ID goes up by one for every input. So when you insert a new row the database will take care of specifying a new number in this field, you don't have to worry about it.|
|Primary Key||This was another attribute that we assigned to ID. It creates a situation where every row in this field has to be unique. All tables should have a primary key, but sometimes you need to create a key that combines multiple fields to ensure uniqueness.|