NYCPHP Meetup

NYPHP.org

[nycphp-talk] Building trees

Brian O'Connor gatzby3jr at gmail.com
Wed Jul 26 19:23:33 EDT 2006


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060726/b00292db/attachment.html>


More information about the talk mailing list