Building a Multi-Page Article System With ASP/PHP - How Everything Will Work (Page 2 of 6 )
If you're a web developer and have business-orientated clients, then I'm sure that you either have -– or will have to –- construct some sort of content management system to manage articles or content. Some people would like to have you think that CMS's (content management systems) are hard to develop. Don't be fooled. They are easy.
The one we are going to build today will let us store and display articles. Each article can have up to 20 pages, each of which will contain a title and some content. We will create one script to create new articles, and another to display them. A MySQL/SQL Server 2000 database will be used to store the articles.
The Database Schema Our database will contain just 2 tables: 1 for the articles and 1 for the pages. Each page will link back to its parent article with the use of a primary key in the articles table, and a foreign key in the pages table.
MySQL Database Details Jump to the MySQL command prompt and run the following code to create a new database and populate it with 2 tables, as described above:
create database myCMS; use myCMS;
create table articles ( articleId int auto_increment not null primary key, title varchar(250), summary text, datePublished timestamp, unique id(articleId) );
create table pages ( pageId int auto_increment not null primary key, articleId int, title varchar(250), content text, unique id(pageId) );
SQL Server 2000 Database Details Use query analyzer to create a new database and populate it with 2 tables, as described above:
create database myCMS go
use myCMS go
create table articles ( articleId int not null primary key identity(1,1), title varchar(250), summary text, datePublished datetime default GETDATE() )
create table pages ( pageId int not null primary key identity(1,1), articleId int, title varchar(250), content text )
Press F5 to execute the queries once you've copied them into the query analyzer window.
Our article system will let us:
Add, edit and delete articles
Shift the page order of each page in our article
Remove all pages in one hit
Delete pages on a page-by-page basis
Update a page once it has already been created
[Note] Our article system will add articles only. It is beyond the scope of this article for me to show you how to load articles back from the database or delete them. [End Note]
Here's a diagram to illustrate the order in which the "add article" form should be completed: