Here is my problem. I want to create a simple message posting system so users can post comments to news stories. I would like the comments to be nested, and not appear as a single long list.


Is there away to retrived all the comments from a table order by the date the parents were added, but nested children under the parent comment, ordered by date, and so on...?

Oracle has this CHILD command will do this, but it seems like this should be possible using GROUP BY. If it is, I can't figure it out.

My Comment table looks like this:

CREATE TABLE `Comments` (
  `ID` int(10) unsigned NOT NULL auto_increment,
  `ArticleID` int(10) unsigned default '0',
  `ParentID` int(10) unsigned default '0',
  `DateAdded` datetime default '0000-00-00 00:00:00',
  `Body` mediumtest,
  PRIMARY KEY  (`ID`),
  KEY `ID` (`ID`)
)

What I would like to get back is:

Comment 1
Comment 2
  Comment 2a
  Comment 2b
Comment 3
  Comment 3a

I can do this in PHP by issuing a seperate query for each parent comment to get the children, and then nesting through them, etc. Or I can get all the records back and sort/nest them once in PHP. I would rather have MySQL just return them all to me in the right order, if possible.

Thanks, Ron



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to