Make PHP Sites

Last updated: 2015-09-13

PHP forum - The database

In this section, we'll go over the tables needed to operate the forum in our lessons. Our forum is going to be about video games.

Requirements

Refer to the Get Started section to know what you need to use this tutorial.

Contents

The MySQL database

To create this forum app, we'll need a database. The forum is dependent, in part, on the database created in the section about user registration. We will be using a MySQL database. Feel free to use any kind with which you are familiar as long as you can adapt our code to fit correctly.

Database name: social

We'll use this database for more social apps

Table: forum_boards

Column Type Description
boardID INT (11) This will be the primary key. It is a unique ID number assigned to each individual board. It should be set to increment automatically.
board VARCHAR (250) This holds the name of the board.
isDeleted Bool A TRUE/FALSE value that will be used to control whether or not the board can be found.
timestamp Timestamp A time stamp, provided by the database, about time the board was last updated.

The table forum_boards will hold the information about each table you want users to use.

After we created this table, we create four boards by inserting values with these queries.

					INSERT INTO forum_boards (board) VALUES('Console games');
					INSERT INTO forum_boards (board) VALUES('Handheld games');
					INSERT INTO forum_boards (board) VALUES('Computer games');
					INSERT INTO forum_boards (board) VALUES('Mobile games');
				

With this table and those four rows, we'll provide our users with four forum boards to interact.

Table: forum_threads

Column Type Description
threadID INT (11) This will be the primary key. It is a unique ID number assigned to each individual thread. It should be set to increment automatically.
boardID INT (11) The identification number of the board each thread belongs to.
userID INT (11) The identification number of the user who created the thread.
title TEXT The string of text the user enters as the title of the thread. You can set it to a limited number of letters.
content LONGTEXT The string of text the user entered as the body of their thread.
comments INT (11) The number of comments a thread has received.
created INT (11) The numberic value of the time a thread was created
isDeleted Bool A TRUE/FALSE value that will be used to tell if a user has canceld there account or has been blocked.
timestamp Timestamp A time stamp, provided by the database, about time the thread was last updated.

This table will hold every thread created by a user for all of the boards.

We'll use all of these columns to display the correct information on a board and most of them to view a single thread.

Table: forum_comments

Column Type Description
commentID INT (11) This will be the primary key. It is a unique ID number assigned to each individual comment. It should be set to increment automatically.
threadID INT (11) The identification number of the thread each comment belongs to.
userID INT (11) The identification number of the user who created the comment.
content LONGTEXT The string of text the user entered as their comment.
created INT (11) The numberic value of the time a comment was created
isDeleted Bool A TRUE/FALSE value that will control whether or not the comment can be viewed.
timestamp Timestamp A time stamp, provided by the database, about time the comment was last updated.

Every comment will be held in this table for all of the boards.

Table: users

Column Type Description
username VARCHAR (250) The username belonging to a single user. This value does not exist in the section about user registration, but it can be added to the registration form and users table for the registration process.

There was no username value set up in the instructions about user registration. The instructions can be modified to include a username value. To help protect the user's identity, we want want to have their posts listed by a username instead of their real name and/or email address.

Tables completed

Once you have those three tables ready and a change to the users table, we can begin displaying the forum to users.

« back to forum instructions

Contact us

Questions or problems? Want to contribute to this tutorial or others?

Contact us