|
|
|
|
![]() ![]() |
Jun 3 2008, 05:40 PM
Post
#1
|
|
|
Advanced Member Group: [HOSTED] Posts: 177 Joined: 25-December 07 Member No.: 27,129 |
Hello,
One of my first ever projects I embarked on when I began to understand PHP well was a forum system. I've decided to begin writing a tutorial to help people start one of their own. The code for this project is based on that of OakumBoard/cBoard, my own forum software which can be seen running at www.sonicxtremegm.co.cc Anyways, time to start off, you must run this SQL query on an SQL database with a name of your choice: CODE s CREATE TABLE `forums` ( `id` int(3) NOT NULL auto_increment, `name` varchar(80) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3; INSERT INTO `forums` (`id`, `name`) VALUES (1, 'Test Forum'), CREATE TABLE `members` ( `id` int(4) NOT NULL auto_increment, `username` varchar(65) NOT NULL default '', `password` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3; CREATE TABLE `replies` ( `topicid` int(4) NOT NULL, `reply_id` int(4) NOT NULL, `reply_user` varchar(50) NOT NULL, `reply_text` longtext NOT NULL, `reply_datetime` varchar(25) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `topics` ( `id` tinyint(4) NOT NULL auto_increment, `title` varchar(180) NOT NULL, `text` longtext NOT NULL, `datetime` varchar(30) NOT NULL default '0', `user` varchar(80) NOT NULL, `reply` int(4) NOT NULL, `forumid` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6; Now, you create a file called conf.php. Inside it should be the text: CODE <?php $host= "[b]localhost[/b]"; // Host name $username="[b]admin[/b]"; // Mysql username $password="[b]adminone[/b]"; // Mysql password $db_name= "[b]admindb[/b]"; // Database name mysql_connect("$host", "$username", "$password")or die("Failed to connect to DB server"); mysql_select_db("$db_name")or die("Failed to select DB"); ?> Replace the bolded areas with the appriate value for your data. |
|
|
|
Jun 17 2008, 02:55 PM
Post
#2
|
|
|
Way Out Of Control - You need a life :) Group: [MODERATOR] Posts: 1,969 Joined: 16-August 05 Member No.: 7,896 |
Sorry for the contradiction, Miles. I would not say that this is a tutorial : this post shows the very nice program you made, it does not teach php.
However, I find your php-by-example approach very constructive. That's why I moved your topic here, where is most probably it's place. Regards Yordan |
|
|
|
Jun 17 2008, 04:44 PM
Post
#3
|
|
|
Kinda N00B Group: Members Posts: 208 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
I don't think you are done with this script or :S?
Because the only thing you have here is the MySQL table, and the database-connection file.. |
|
|
|
Jun 18 2008, 04:40 PM
Post
#4
|
|
|
Advanced Member Group: [HOSTED] Posts: 177 Joined: 25-December 07 Member No.: 27,129 |
Haven't finished writing it out yet. By the way, there is more below.
You are now going to create the main files: index.php. This contains nearly all the coding for the forum. You will place the following within it: CODE <?php $name = $_COOKIE['username_cb']; if ( $name == "" ) { $name="Guest"; } //--------------------------------------------------------- // Include all necessary files and find the requested page //--------------------------------------------------------- include "conf.php"; //--------------------------------------------------------- // Prepare a few things //--------------------------------------------------------- $page = $_GET['p']; if ($page=="") { $page = main; } switch ($page) { //--------------------------------------------------------- // Show the list of forums //--------------------------------------------------------- case "showforums": echo "<table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#CCCCCC\"> <tr> <td width=\"6%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>#</strong></td> <td width=\"76%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>Forum</strong></td> <td width=\"18%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>Last Topic</strong></td> </tr> "; $sql="SELECT * FROM forums ORDER BY id ASC"; // Now to get the forums list done $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo " <tr> <td bgcolor=\"#FFFFFF\">".$rows['id']."</td> <td align=\"left\" valign = \"top\" bgcolor=\"#FFFFFF\"><B><a href=\"index.php?p=showtopics&id=". $rows['id'] ."\">". $rows['name'] ."</a></b><BR>". $rows['desc'] ."</td> <td bgcolor=\"#FFFFFF\">".$rows['lastpost']."</td>"; } //Join it all up echo "</table>"; break; } ?> More parts of this tutorial coming soon! |
|
|
|
Jun 18 2008, 07:07 PM
Post
#5
|
|
|
Sparkx Group: [HOSTED] Posts: 339 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 |
Forums are often very large and require many pages. Most forum softwares take a long time to make. The one I made however only was a few PHP pages and already out ranks every other one I have seen but the method that you are using will take a lot more space then mine did. I would recommend that you finish your entire tutorial on one post and rather then posting code just make a .txt file, upload it and link to it. This would really help people follow your post's easier. Your post could be a good tutorial if you were to put all the code together but at the moment all I see is a good tutorial in the making that isn't quite ready to be posted yet.
Good luck, Sparkx |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 22nd August 2008 - 05:05 AM |