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 开发者_JS百科`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.
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.
Row 1: commentId=1;parent=0 (this is a parent comment)
Row 2: commentId=2; parent=1 (this means its a child of comment 1)
Row 3: commentid=3; parent=2 (this is a child of 2nd comment)
Row 4: commentid=4; parent=0 (this is the "fresh second" comment)
makes sense ?
精彩评论