Re: [PHP] Recursion and threaded message boards...

2007-08-10 Thread Richard Lynch
On Fri, August 10, 2007 11:23 am, Tony Di Croce 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)...

What you describe will "work" if you don't care about performance...

If there's any heavy activity at all, you'll be swamping your Database
in recursive "child" lookup queries.

Google for "SQL Tree Traversal" and you should find quite a few
solutions.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recursion and threaded message boards...

2007-08-10 Thread Børge Holen
On Friday 10 August 2007 18:29, Stephen wrote:
> --- Tony Di Croce <[EMAIL PROTECTED]> 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?
>
> You are reinventing the wheel here. Why?

Why bother doing with these questions when he only asks for advice... 
FOR THE SAKE OF DOING IT!!!


>
> There are a number of open source PHP message board
> scripts. Check those out, even if just to learn as
> examples.

Ah and here you come through =D

>
> Stephen

-- 
---
Børge
http://www.arivene.net
---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recursion and threaded message boards...

2007-08-10 Thread Richard Davey
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"

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recursion and threaded message boards...

2007-08-10 Thread Stephen
--- Tony Di Croce <[EMAIL PROTECTED]> 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?

You are reinventing the wheel here. Why?

There are a number of open source PHP message board
scripts. Check those out, even if just to learn as
examples.

Stephen

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Recursion and threaded message boards...

2007-08-10 Thread Tony Di Croce
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)...

td

-- 
Publish technical articles @ skilledwords.com and get 100% of the
ad-revenue!
http://www.skilledwords.com