Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.