NYCPHP Meetup

NYPHP.org

[nycphp-talk] Building trees

Jim Hendricks jim at bizcomputinginc.com
Wed Jul 26 21:31:35 EDT 2006


I've got somewhere in my library of routines a set of routines for trees 
using nested subsets.  It worked with mysql and if I recall correctly 
the queries were all simple enough without the need for subqueries.  I 
also seem to recall Hans working on a nested subset lib and discussing 
it on this list.

Jim

Rob Marscher wrote:
> Maybe try using a modified preorder tree.  This article explains it in 
> MySQL/PHP terms - 
> <http://www.sitepoint.com/article/hierarchical-data-database/2>.  If you 
> organize your tree that way, it will prevent the need for recusion.  The 
> only downside is it's more difficult to understand and requires more 
> queries when adding new nodes because you have to update the numbering 
> for the other nodes.  But I recommend it.
>
> FYI, nyphp-mysql is a special list for MySQL related PHP topics - 
> <http://lists.nyphp.org/mailman/listinfo/mysql>
>
> -Rob
>
>
> 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
>>     
> _______________________________________________
> 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
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060726/e48431d1/attachment.html>


More information about the talk mailing list