Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Nested Comments (parent/child) [duplicate]

Possible Duplicate:
Display hierarchical data

I'm looking to create a nested comments system - I realise this has been covered before on SO and the net but I cant seem to get anything to work correctly.

Given the following table structure (which I have created):

CREATE TABLE IF NOT EXISTS `comments` (
  `commentid` int(11) NOT NULL auto_increment,
  `newsid` int(11) NOT NULL,
  `body` text NOT NULL,
  `added` int(11) NOT NULL,
  `parent` int(11) default NULL,
  PRIMARY KEY  (`commentid`)
)

How am I able to the comments in a threaded manner? I'm looking for either a PHP solution of MySQL. I realise that parent holds the commentid (parent) of the comment.


1 Answers

When you save a reply, assign the parent id to the comment id of the one of which you are replying to.

When generating the HTML, recursively print the child comments of any parent.

like image 155
alex Avatar answered May 05 '26 01:05

alex