Post by evogund on Jul 27, 2011 4:40:49 GMT
FIRST OFF, YOU DO NOT HAVE MY PERMISSION TO USE THIS AS A BASE FOR AN ACTUAL SOFTWARE, IT IS A BASE FOR MY OPEN SOURCE SOFTWARE. LEARNING RIGHTS ONLY.
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
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.
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.
Explanation: What this code is doing is connecting to the database and retrieving the information we specified and placing it into an html table.
[html]$cat = "SELECT * FROM cat ORDER BY cid asc";[/html]
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.
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: ideadome.ulmb.com/yo.php
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
<?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.
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.
<?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.
[html]$cat = "SELECT * FROM cat ORDER BY cid asc";[/html]
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.
$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: ideadome.ulmb.com/yo.php