Jump to content

PHP tree-like forum


Laash

Recommended Posts

Hello everyone.

I'm new here and I have a question.

 

I know about php forums like phpbb and invision power board, but I am looking for a forum which is built in tree-structure, a non-threaded one.

I want messages to appear right under the other, with a little margin. Well, you get me.

I couldn't find any freeware/non-freeware forum like that on Google.

Can anyone please help me on that matter?

 

Thanks a lot!

Lasash.

Link to comment
https://forums.phpfreaks.com/topic/125259-php-tree-like-forum/
Share on other sites

  • 4 weeks later...

I came up with this:

 

<?php

if ($connection = mysql_connect ('localhost', 'username', 'password'))
{
if (mysql_select_db ('database', $connection))
{
	$query = 'SELECT * FROM `comments` ORDER BY `comment_root`, `comment_parent`, `comment_id` ASC';

	if ($result = mysql_query ($query, $connection))
	{
		$comments = array ();

		while ($comment = mysql_fetch_assoc ($result))
		{
			$comments[] = $comment;
		}
	}
}
}

function OutputTree ($comments, $parent_id)
{
foreach ($comments as $comment)
{
	if ($comment['comment_parent'] == $parent_id)
	{
		print '<blockquote>';
		print $comment['comment_poster'].' said: '.$comment['comment_message'];

		OutputTree ($comments, $comment['comment_id']);

		print '</blockquote>';
	}
}
}

OutputTree ($comments, 0);

?>

 

Table structure:

 

CREATE TABLE IF NOT EXISTS `comments` (
  `comment_id` bigint(20) unsigned NOT NULL auto_increment,
  `comment_root` bigint(20) unsigned NOT NULL,
  `comment_parent` bigint(20) unsigned NOT NULL,
  `comment_poster` varchar(64) NOT NULL,
  `comment_message` text NOT NULL,
  PRIMARY KEY  (`comment_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

Not the most efficient, especially if there are hundreds of comments.

Link to comment
https://forums.phpfreaks.com/topic/125259-php-tree-like-forum/#findComment-665378
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.