Simply Cutting Edge
Welcome Guest [Log In] [Register]
Welcome to zetaNetwork. We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as viewing zetaNetwork exclusive tutorials and articles, and access to our code snippets section. Registration is simple, fast, and completely free.


Click Here To Register


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
FORUM SOFTWARE TUTORIAL
Topic Started: May 20 2011, 12:16 PM (7,148 Views)
Connor
Rules
Newbie
Making a forum software
Difficulty: Medium
Time: 45 minutes - 1 hour



hi there!
I may not be the best with php but I generally know my way around using it. I started off with php wanting to make my own forum software. I am sure there are others around here who wish to do the same. So my ultimate thoughts were to try to help you all out.

Start off by creating your database file in order to connect to the mysql server
Code: HTML
 
<?php
$mysql_host = "mysql";
$mysql_database = "DATABASE NAME HERE";
$mysql_user = "DATABASE USERNAME HERE";
$mysql_password = "PASSWORD HERE";

$connection = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die("Could not connect to MySQL");
mysql_select_db($mysql_database, $connection) or die ("Database cannot be found.");
?>

What the above code does is connect you to your database. If your settings are wrong it will display "Could not connect to MySQL", if they are right but there is no database in your account, you will see, "Database cannot be found." and it will kill the connection.

Next create your MySQL database tables.
My settings are below.
Code: HTML
 
CREATE TABLE `cat` (
`cname` varchar(500) NOT NULL,
`cid` tinyint(99) NOT NULL AUTO_INCREMENT,
`cdesc` varchar(1000) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `forum` (
`fname` varchar(200) NOT NULL,
`fid` tinyint(99) NOT NULL AUTO_INCREMENT,
`pid` tinyint(99) NOT NULL,
`fdesc` varchar(9999) NOT NULL,
PRIMARY KEY (`fid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `settings` (
`title` varchar(20) NOT NULL,
`online` tinyint(200) NOT NULL DEFAULT '1',
`offlinemsg` varchar(9999) NOT NULL DEFAULT 'We are sorry. The administrator of this forum has turned the board offline for mantinance, please check again later.',
KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

That is simply a database query. You may be able to use these settings to create an install file if needed. I will make an install file tutorial later on.

Next you will start your coding. I will not go very far in depth or even show you my entire code. Just the PHP/SQL parts. The html, you can do on your own.

Code: HTML
 
<?php
include ('dbconnect.php');
echo '<table>';
$cat = "SELECT * FROM cat ORDER BY cid asc";
$result = mysql_query($cat) or die(mysql_error());
while($catvar = mysql_fetch_array($result)){
echo '<tr><th colspan="1">'.$catvar['cname'].'<small> ( '.$catvar['cdesc'].' ) </small></th></tr>';
$forum = "SELECT * FROM forum WHERE forum.pid = ".$catvar['cid']." ORDER BY fid asc";
$result2 = mysql_query($forum) or die(mysql_error());
while($forumvar = mysql_fetch_array($result2)){
echo '<tr><td ><a href="./forum.php?='.$forumvar['fid'].'">'.$forumvar['fname'].'</a><br />'.$forumvar['fdesc'].'</td></tr>';
}
}
echo '</table>';
?>

Explanation: What this code is doing is connecting to the database and retrieving the information we specified and placing it into an html table.
Code: HTML
 
$cat = "SELECT * FROM cat ORDER BY cid asc";

This connects to your dbconnect file and then retrieves everything (*) from the cat table and order's them by the categories id (cid) in ascending order.

Code: HTML
 
$forum = "SELECT * FROM forum WHERE forum.pid = ".$catvar['cid']." ORDER BY fid asc";

This does a very similar thing. The main difference is, it checks the forum.pid (parent id) field and displays any that have the same pid as any of the categories (cid) therefor simply connection the child (forum) with it's parent (category).


That was a simple php forum software tutorial.
I may go a bit more in depth later on but hopefully this helps a few people out.
Enjoy!

Styled Demo: http://ideadome.ulmb.com/yo.php
Edited by Connor, May 20 2011, 12:17 PM.
Quote:
 

[12:59] Connor: Last night I coded from 3AM to 5AM
[12:59] Connor: Was on a roll, couldn't stop hahaa
[12:59] Alban: LOL
[12:59] Alban: I love those "coding highs" :D
[12:59] Connor: xD
[12:59] Alban: And yes, I just made that up XD
[12:59] Connor: Quoted for my ZN sig :P


Alban is dah man ;)
Offline Profile Quote ^
 
Pro
Member Avatar
Underground Coding

Nice start on this. Looking forward to an update or expansion :)

This tutorial has been found to be about PHP and has been moved to the PHP section.

Pro | zetaNetwork Staff
Pro | zetaNetwork Instructor & Admin
I Coded Most Of The Smexy Stuff You See :P
PM Me Any Questions
Need live support? Click here.
Offline Profile Quote ^
 
Connor
Rules
Newbie
Thanks :)
Quote:
 

[12:59] Connor: Last night I coded from 3AM to 5AM
[12:59] Connor: Was on a roll, couldn't stop hahaa
[12:59] Alban: LOL
[12:59] Alban: I love those "coding highs" :D
[12:59] Connor: xD
[12:59] Alban: And yes, I just made that up XD
[12:59] Connor: Quoted for my ZN sig :P


Alban is dah man ;)
Offline Profile Quote ^
 
VoidPC
Rules
Getting Into The Groove
Connor
May 20 2011, 12:16 PM
CREATE TABLE `cat` (
`cname` varchar(500) NOT NULL,
`cid` tinyint(99) NOT NULL AUTO_INCREMENT,
`cdesc` varchar(1000) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Questions:
1. Is it okay tu make a variable without using (`) ?
2. I don't understand the part in yellow color except the semi-colon. >.<
Offline Profile Quote ^
 
Tajio
Rules
Newbie
Fabolous, I always wanted to play about with a custom forum software :)
Offline Profile Quote ^
 
Connor
Rules
Newbie
VoidPC
Jun 3 2011, 01:38 AM
Connor
May 20 2011, 12:16 PM
CREATE TABLE `cat` (
`cname` varchar(500) NOT NULL,
`cid` tinyint(99) NOT NULL AUTO_INCREMENT,
`cdesc` varchar(1000) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Questions:
1. Is it okay tu make a variable without using (`) ?
2. I don't understand the part in yellow color except the semi-colon. >.<
I believe that making a variable without the (') would be okay, but I make the tables and fields from scratch rather than running the query I posted so I am not entirely sure.

The charset is what determines what encoding is used. So certain characters won't be displayed I think...
And the Engine is which engine is used. I think there is MySQL, MySQL Li, etc. but I am not entirely sure about that either.

And thanks everyone for the feedback :)
Quote:
 

[12:59] Connor: Last night I coded from 3AM to 5AM
[12:59] Connor: Was on a roll, couldn't stop hahaa
[12:59] Alban: LOL
[12:59] Alban: I love those "coding highs" :D
[12:59] Connor: xD
[12:59] Alban: And yes, I just made that up XD
[12:59] Connor: Quoted for my ZN sig :P


Alban is dah man ;)
Offline Profile Quote ^
 
1 user reading this topic (1 Guest and 0 Anonymous)
ZetaBoards - Free Forum Hosting
Enjoy forums? Start your own community for free.
« Previous Topic · Tutorials · Next Topic »
Add Reply