Laash Posted September 22, 2008 Share Posted September 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125259-php-tree-like-forum/ Share on other sites More sharing options...
jordanwb Posted October 14, 2008 Share Posted October 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125259-php-tree-like-forum/#findComment-665378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.