Re: Nested database loops and completing an unordered list....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> My usual approach to a problem like this to to includes a parent column in the table
> 
> ID (int pk)
> Parent ( default null ) // no parent
> Item
> Itemtype
> [etc]
> 
> Parent will then hold either a null if a top level item, or a structured path ( 1/10/24 ) that notes the parents of the item all the way up to the parent. That way, a single query will get you all items in that parent's lineage to whatever depth is needed by using the child's value
> 
> Select * from table where parent = '1/10' 
> 
> Would retrieve all items that are children of a top level of 1 and a second level of 10

I would do that under normal circumstance but I cannot modify the client's table in any way shape or form. I am considering the COMPANY_ID to be the parent at this point and I can get all who belong to a company. I just need to turn that lineage into a tree.
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux