[nycphp-talk] Building trees
max goldberg
max at idsociety.com
Wed Oct 16 18:39:24 EDT 2002
I wrote something similar to what you are describing for a personal
project a while back. On the SQL side it's a pretty simple layout,
every record has a parent id, and from that I can figure out all the
children by making a quick and dirty index before hand.
Check out (sorry if the url offends)
http://www.fuck.org/~max/traverse.phps for the example
and http://www.fuck.org/~max/traverse.php for the output.
Sorry if the code is a bit dirty, it's kind of old. =)
-Max
Jim Hendricks wrote:
> 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
>
>
>
>
>
>
> --- Unsubscribe at http://nyphp.org/list ---
>
>
More information about the talk
mailing list