You may want to check out using Nested Sets instead of a Parent-Child-ID
system. I think it's an easier system for representing hierarchies. Here is
a good article on the system:,289483,sid13_gci537290,00.html

Google for Nested Sets +sql or something and there are more articles out
there. It's sort of confusing in the beginning. If you have any questions,
let's take it off the PHP list.

---John Holmes...

----- Original Message -----
From: "David Elliott" <[EMAIL PROTECTED]>
To: "Adam Voigt on PHP-DB" <[EMAIL PROTECTED]>
Sent: Tuesday, November 26, 2002 9:41 AM
Subject: [PHP-DB] Re: MySQL/PHP Iterative Tree

> Hash: SHA1
> Hello Adam
> On 26 November 2002 at 08:25:22 -0500 (which was 13:25 where I live) Adam
> Voigt emanated these words of wisdom
> < ... >
> > Ok, and I am using this structure to make a kind of drill down
> > structure, so the top level would be where parentid = '0', then
> > you take those id's and select from this table where parentid is
> > equal to those id's, and now your starting to navigate through
> > the tree, and so on.
> > Now, the real question, I have found a Javascript menu script which
> > will let users of the site click on it, and then click on the submenu
> > and down and down through all the level's that might dynamically exist,
> Be careful of the size and the time it takes to build a big tree.
> > but I can't for the life of me figure out how to recursively get the
> > name and id for each row (which is what I need to build the menu and
> > make link's out of each item), for as many sublevel's as there might be
> > (infinite). Am I missing something, is there a simple logical way to do
> > this recursively? Or if there's a semi-complex way, anyone got a script
> > example? I'd very much appreciate it.
> This is not much help but have done something like that in MSSQL with
> procedure (about 120 to 150 lines of SQL).
> The logic went something like.
> get all top level
> put into a temptable_1
> go through temptable_1
>   put line into temptable_2 noting level
>   add on any children for line into temptable_2
> next line of temptable_1
> copy temptable_2 to temptable_1
> keep going through temptable_1 until there is no more children at last
> I also used a separate table for the links this way it is easier to go
> up and down the tree.
> What would be nice is to do it dynamically and display only the tree that
> you need and just get the data for the children when needed. eg like
> M$ site
> - --
>  TTFN,                     _______________________________________________
>   David                   |    David  Elliott    |   Software Engineer
>  _________________________| [EMAIL PROTECTED] | PGP Key ID 0x650F4534
> | I am Barney of Borg...Sesame Street will be assimilated.
> Version: 6.5.8ckt
> KzmAxhrABe/7JZxw3mvmYkaJ
> =xdTm
> --
> PHP Database Mailing List (
> To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to