6.1. Add a page Column to the entries Table

Your first task is learning to identify what entries belong on what page. Essentially, you need to add a page identifier. This could be a number or a string. Your application is pretty simple, so you can just use the name of the page as your identifier.

To add this to your entries, you need to get back into your database controls, located at http://localhost/phpmyadmin. Open the simple_blog database, then the entries table. You need to add a column called page to the entries table, which will hold the name of the page to which each entry belongs.

This column cannot be blank, or the entries will get lost. To avoid this, you can set the column to NOT NULL and provide a default value. Most entries will end up on the blog page, so set the default to "blog." Finally, for organizational purposes, you want to put the column right after the id column; you can accomplish this in your query by using AFTER id.

Additionally, you can speed up your queries by adding an index to the page column. This is as simple as appending ADD INDEX (page) to the end of the query, separated by a comma. The full query looks like this:

ALTER TABLE entries
ADD page VARCHAR(75) NOT NULL DEFAULT 'blog'
AFTER id,
ADD INDEX (page)

Now execute the preceding query in the SQL tab of http://localhost/phpmyadmin. When the query finishes, click the Browse tab to verify that the page column has been created and that all the pages have been identified as blogs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.136.142