1. Demand analysis
-
Start a new discussion topic by publishing an article
-
Post an article to reply to an existing article
-
View published articles
-
View conversation topics in the forum
-
Check the relationship between articles, that is, check which article is a reply to another article
2. Solution
2.1 Forum design
2.2 Files used in the web forum application
file name |
Types of |
description |
index.php |
application |
The user enters the home page that the site sees. Include an expandable and deleteable list of all articles in the site |
new_post.php |
application |
Form for publishing new articles |
store_new_post.php |
application |
Save the post entered in the new_post.php form |
view_post.php |
application |
Display a single article and a list of articles that responded to it |
treenode_class.php |
Function library |
Contains the node class, we will use it to show the inheritance relationship of the article |
include_fns.php |
Function library |
Put all other function libraries used in this program together (other library type files are listed here) |
data_valid_fns.php |
Function library |
Data verification function |
db_fns.php |
Function library |
Database connection function |
discussion_fns.php |
Function library |
Functions for handling storage and retrieval of published articles |
output_fns.php |
Function library |
Function to output HTML |
create_database.sql |
SQL |
SQL script of the database needed to establish the program |
3. Implement the database
CREATE DATABASE discussion; #Create forum database USE discussion; #Use forum database CREATE TABLE header #Create data header table (parent INT NOT NULL, # parent article postid poster CHAR(20) NOT NULL, #The author of the article title CHAR( 20) NOT NULL, #The title of the article children INT DEFAULT 0 NOT NULL, #Whether there is a reply to this article, 0 none, 1 yes, default 0 area INT DEFAULT 1 NOT NULL, #Ready for expansion, to achieve multiple forums Multiple sections posted datetime NOT NULL, #The publication time and date of the article postid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY #The unique ID of each article); CREATE TABLE body #Create a body table (postid INT UNSIGNED NOT NULL PRIMARY KEY , #Each article’s unique ID message text #the body of the article);GRANT SELECT,INSERT,UPDATE,DELETEON discussion.*TO discussion@localhost IDENTIFIED BY'password';
4. Implement the source code
Download link: A simple PHP Web forum