NYCPHP Meetup

NYPHP.org

Building trees

Jim Hendricks(Biz Computing) jim at bizcomputinginc.com
Wed Oct 16 13:12:12 EDT 2002


I know this is a SQL question, but since most apps deal with SQL, I 
figured I'ld ask here since the app is using PHP and MySQL.

I have a table that establishes an entity that may have a parent from 
the same table.  I would like to display the data in a tree format where 
all items with a ParentID of 0 ( no parent ) are listed with children 
indented under the parent.  The nesting can be infinite, but 
realistically will only be 2 or 3 levels deep.  I can see how to do this 
through a whole series of queries, but can see how the performance of 
such a design could be very poor if there is a lot of items.  Looking 
for any ideas, even if they would require a table design mod to make the 
queries simpler.  The current design is a single table with ID, and 
ParentID and whatever other info needed for the item.

Thanks, Jim







More information about the talk mailing list