Re: Create a hierarchical hash from flat source
| From: | Simon J Welsh | Date: | Wed, 22 Jun 2011 21:57:26 +0000 |
| Subject: | Re: Create a hierarchical hash from flat source | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313657@lists.php.net to get a copy of this message | ||
On 23/06/2011, at 9:53 AM, Scott Baker wrote:
> I have a bunch of records in a DB that look like
>
> id | parent_id
> --------------
> 1 | 4
> 2 | 4
> 3 | 2
> 4 | 0
> 5 | 2
> 6 | 1
> 7 | 3
> 8 | 7
> 9 | 7
>
> I want to build a big has that looks like:
>
> 4 -> 1 -> 6
> -> 2 -> 3 -> 7 -> 9
> -> 5 -> 8
>
> I'm like 90% of the way there, but I can't get my recursive assignment
> to work. Has anyone done this before that could offer some pointers?
> Here is my sample code thus far:
>
> http://www.perturb.org/tmp/tree.txt
>
> I can get one level of depth, but nothing more than that :(
I haven't looked that much into your code, but:
$children = find_children($id,$list);
$list is never defined.
---
Simon Welsh
Admin of http://simon.geek.nz/