HomePHP Creating a Simple Threaded Discussion Forum
Creating a Simple Threaded Discussion Forum
Most websites have some method of interacting with a visitor. Some have a chat system and others have shoutboxes or other ways to attract the visitor to return. One of the most used methods is a discussion forum. And this is what we are going to create and discuss in this article (the first of two parts).
Specifically, we're going to create a threaded discussion forum. Why do we want a THREADED discussion forum? Well, it's simple: a threaded discussion forum allows a visitor to make multiple replies to the same topic in an ordered fashion. This gives us a discussion tree, with the topic being at the heart of it.
Our Forum is going to have four main pages:
Index.php - To let users view a list of all the parent thread (topic) titles.
Viewarticle.php - To let users view a full parent message and replies.
Postre.php - To let users reply to a parent thread.
Post.php - To let users create a new thread (or topic).
We will need some additional files:
Tutstyle.css - CSS style definitions.
fns_all.php - Contains all the functions used in the forum.
config.php - Contains the database connection settings.
We will also create an "images" folder in the same directory.
Here's the table for our forum:
CREATE TABLE `test` ( `uid` int(5) unsigned NOT NULL auto_increment, `parent` int(5) NOT NULL default '0', `name` varchar(90) NOT NULL default '', `title` varchar(100) NOT NULL default '', `message` text NOT NULL, `date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`uid`)
The field called "uid" is a unique, autonumber field, which will identify each thread in the discussion forum. The field "parent" represents the ID of the parent thread for the current thread (if any), and will be 0 for all new threads. This structure gives us the ability to add as many replies to a thread as we like.
Copy and paste the table structure in your phpAdmin client: