Re: Recursion and threaded message boards...
| From: | Richard Davey | Date: | Fri, 10 Aug 2007 16:40:54 +0000 |
| Subject: | Re: Recursion and threaded message boards... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-260608@lists.php.net to get a copy of this message | ||
Hi Tony,
Friday, August 10, 2007, 5:23:28 PM, you wrote:
> I have to write some PHP backend code for a threaded message board.
> The db has a message table, and each message has a parent id.
> Does anyone have any advice for someone whos never done this in PHP?
> I'm currently thinking that I write function that takes a db row as
> an argument, and initially, it is passed the root node of the whole
> tree. It is also probably passed a string variable.
> The first thing it will do is append the code for itself to the string.
> Then it will query the DB for all its children (with an order by post
> timestamp), and for every child, it will call itself on that child row.
> Am I on the right track? (I've done simmilar things in C++, just not in
> PHP)...
To be honest this is less of a PHP issue (at this stage) and more of a
SQL one. What SQL package are you using? (MySQL? if so v4 or v5?). I
would strongly consider looking at using a nested set system for the
structure (or at least a derivative of it, there are many good ones
out there) in combination with a standard parent/child hierarchy.
You can wrap up nearly all of the complexity of this requirement (i.e.
the tree walking / retrieval) on a stored procedure level with some
decent table design.
Cheers,
Rich
--
Zend Certified Engineer
http://www.corephp.co.uk
"Never trust a computer you can't throw out of a window"