NYCPHP Meetup

NYPHP.org

[nycphp-talk] Building trees

bruce at mtiglobal.com bruce at mtiglobal.com
Thu Oct 17 05:47:19 EDT 2002


Can a parent by a child and a child be a parent?

Is so, perhaps you could have another table where the relationship is
established.

tblObjects:
objectID
fname
lname
etc. fields

tblRelationships:
relationship  - autonumber
parent
child

where parent and child are the id's from tblObjects.

I could probably be more clear if I knew the specifics of what the
entities you are using are.

>From this you could then select from the two tables.

- Bruce

> 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