klange
July 11th, 2009, 01:25 PM
Hey, you read this: I had completely forgotten about this thing, I'll do it this week (not now, it's late >_>) okay?
Introduction
Alright, so, I felt I'd write a tutorial on how to write a discussion forum from scratch. I'm going to do this in multiple installments, so bear with me. I'll only go into the "what you need" for today, and then move into the basics tomorrow. Hopefully by next Tuesday this tutorial will be done...
Tools Required
- PHP 5
- Apache or similar (I'm not going to show you how to set it up)
- MySQL
- MySQL GUI Tools or similar package (I like the cross-platform Administrator and Query Browser, good solid tools, and I'll be using them in my examples)
- Notepad++, Gedit, or other similar editor
If you're not up to the task of setting this stuff up and don't have your own hosting somewhere, you can get a package like XAMPP (http://www.apachefriends.org/en/xampp.html). It's easy to set up on Windows and Linux and provides a simple interface to get your server running with everything you need.
Structure of this Tutorial
We'll first explore the basic design of a simple forum and look at the aspects we want to replicate. We'll then cover the basics of our MySQL table structures and how they will work in our code. Then we'll get to work on the actual coding in PHP. Finally, we'll style the forum with some CSS. Our final product will be a flat forum with user accounts, including avatars, signatures and bbCode.
Part I: Forum Basics
Let's look at the forum we're on now: vBulletin is primarily a flat-thread forum with categories, boards and threads - the same model we'll be using. This has remained the dominant layout for community forums for years. The other layout you tend to find is nested tree replies, but it's very complicated and we won't get into it.
Category
_Board
__Thread
___Post
___Post
__Thread
___Post
___Post
_Board
__Thread
___Post
___Post
__Thread
___Post
___Post
Category
_Board
__Thread
___Post
___Post
Part II: SQL Tables
SQL is the basis for data storage on the Internet. Forums, CMSes, blogs - they all store data, and most all of them do it with SQL. There are a few different forms of SQL: MySQL, MSSQL, PL/SQL, etc., but MySQL is the most popular, mostly because it is free and open-source.
Our SQL is fairly simple, and you'll want to get your editor ready and make these now:
categories
id (int, primary key, auto-increment)
name (string)
boards
id (int, primary key, auto-increment)
name (string)
perms (int, default=0, not-null)
threads
id (int, primary key, auto-increment)
title (string)
author (int, not-null)
content (TEXT)
posts
id (...)
author (int, no-null)
content (TEXT)
users
id (...)
name (string)
level (int, default=0, not-null)
signature (string)
avatar (string)
(I'll put up SQL that generates these tomorrow; the rest of the tutorial should be up later today)
Introduction
Alright, so, I felt I'd write a tutorial on how to write a discussion forum from scratch. I'm going to do this in multiple installments, so bear with me. I'll only go into the "what you need" for today, and then move into the basics tomorrow. Hopefully by next Tuesday this tutorial will be done...
Tools Required
- PHP 5
- Apache or similar (I'm not going to show you how to set it up)
- MySQL
- MySQL GUI Tools or similar package (I like the cross-platform Administrator and Query Browser, good solid tools, and I'll be using them in my examples)
- Notepad++, Gedit, or other similar editor
If you're not up to the task of setting this stuff up and don't have your own hosting somewhere, you can get a package like XAMPP (http://www.apachefriends.org/en/xampp.html). It's easy to set up on Windows and Linux and provides a simple interface to get your server running with everything you need.
Structure of this Tutorial
We'll first explore the basic design of a simple forum and look at the aspects we want to replicate. We'll then cover the basics of our MySQL table structures and how they will work in our code. Then we'll get to work on the actual coding in PHP. Finally, we'll style the forum with some CSS. Our final product will be a flat forum with user accounts, including avatars, signatures and bbCode.
Part I: Forum Basics
Let's look at the forum we're on now: vBulletin is primarily a flat-thread forum with categories, boards and threads - the same model we'll be using. This has remained the dominant layout for community forums for years. The other layout you tend to find is nested tree replies, but it's very complicated and we won't get into it.
Category
_Board
__Thread
___Post
___Post
__Thread
___Post
___Post
_Board
__Thread
___Post
___Post
__Thread
___Post
___Post
Category
_Board
__Thread
___Post
___Post
Part II: SQL Tables
SQL is the basis for data storage on the Internet. Forums, CMSes, blogs - they all store data, and most all of them do it with SQL. There are a few different forms of SQL: MySQL, MSSQL, PL/SQL, etc., but MySQL is the most popular, mostly because it is free and open-source.
Our SQL is fairly simple, and you'll want to get your editor ready and make these now:
categories
id (int, primary key, auto-increment)
name (string)
boards
id (int, primary key, auto-increment)
name (string)
perms (int, default=0, not-null)
threads
id (int, primary key, auto-increment)
title (string)
author (int, not-null)
content (TEXT)
posts
id (...)
author (int, no-null)
content (TEXT)
users
id (...)
name (string)
level (int, default=0, not-null)
signature (string)
avatar (string)
(I'll put up SQL that generates these tomorrow; the rest of the tutorial should be up later today)