[nycphp-talk] Building trees
Jon Baer
jonbaer at jonbaer.com
Wed Jul 26 21:50:41 EDT 2006
I beleive what you are looking to get into is nested sets ...
http://www.edutech.ch/contribution/nstrees/index.php
What you have sounds like you are on the right track ...
There is also a PEAR package for doing NS w/ dbs:
http://pear.php.net/package/DB_NestedSet
- Jon
On Jul 26, 2006, at 7:23 PM, Brian O'Connor wrote:
> Hello all,
>
> Right now I'm building a site that has a "tree" like structure, and
> right now in order to get the children I'm using a recursive
> function to get them all, works fine, but that strikes me as
> inefficient and I'm trying to find a way to get it with one query,
> rather than a variable amount of queries based on how many 'events'
> a user has.
>
> I looked through the archives of the list to find a thread exactly
> like this, but was in 2002 apparently before MySQL had subqueries
> (and apparently that's what you need; I'm not sure but that's what
> I gathered looking through the responses).
>
> I was wondering if anyone could help me out.
>
> Right now all the events are in a table called 'cal_events', each
> row has an id and a parent_id (among other things that I don't
> think are important for this). If you'd like to see the function I
> can certainly post that as well.
>
> All I do is get all the events that have a parent_id of 0 (top
> level), loop through them to get their children, and loop through
> them to get their children etc (in order), and indent them as
> needed on the display side.
>
> Thanks in advance for any ideas.
>
> --
> Brian O'Connor
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
More information about the talk
mailing list