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

From: Date: Fri, 02 Mar 2012 16:06:56 +0000
Subject: Re: Nested database loops and completing an unordered list....
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.general 
Request: Send a blank email to php-general+get-316842@lists.php.net to get a copy of this message
On Fri, Mar 2, 2012 at 7:43 AM, Jay Blanchard <jay.blanchard@sigmaphinothing.org> wrote: >> 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. Would they let you make a copy or a join table where you could build what you need? Then maybe add a stored proc to move data as needed -- Bastien Cat, the other other white meat

« previous php.general (#316842) next »