On 12.06.2004 09:36 (+0200), Ron Gilbert wrote:
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,
you mean mediumtext, right?
   PRIMARY KEY  (`ID`),
   KEY `ID` (`ID`)
I believe the primary key is sufficient.
)

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.

Yes, that's how I do it for a similar problem. You can either run a new query SELECT... WHERE ParentID=... for each ArticleID WHERE ParentID=0 and recurse this for every new ID, or do this yourself in PHP by getting all records in a single step and go through the entire array and scan the IDs for yourself. This shouldn't be too much work to do so I'd suggest you to do some tests to find out what is faster.


I'm not aware of a way to get the nested structure directly from MySQL, but that doesn't have to say too much... ;) I mean I couldn't imagine how this should look like other than a flat array you have to split manually.

--
Yves Goergen <[EMAIL PROTECTED]>

BlackBoard Internet Newsboard System --> blackboard.unclassified.de
Free (GPL), easy to use and install, secure, innovative! (PHP+MySQL)

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



Reply via email to