Welcome Guest, Not a member yet? Register   Sign In
hierarchy system in mysql with php
#10

[eluser]TheFuzzy0ne[/eluser]
Here's a function that doesn't echo anything. It just calls upon itself and builds the string up and passes it back when it's done.

Code:
function doit($tree, $prefix="")
{
    $title = $tree['title'];
    $prefix = ($prefix) ? $prefix.'--'.$title : $title;
    $str = $title."<br />\n";
    if (isset($tree['children']))
    {
        foreach ($tree['children'] as $node)
        {
            $str .= $prefix.'--'.doit($node, $prefix);
            $str .= ( ! isset($node['children'])) ? "<br />\n" : '';
        }
    }
    
    return $str;
}

Hope this helps. You can always add it to your model if you want, but I'd probably keep it as a helper, since it's just formatting data, not actually retrieving any.


Messages In This Thread
hierarchy system in mysql with php - by El Forum - 06-05-2009, 03:09 AM
hierarchy system in mysql with php - by El Forum - 06-05-2009, 03:21 AM
hierarchy system in mysql with php - by El Forum - 06-05-2009, 04:11 AM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 12:59 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 01:01 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 01:08 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 03:22 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 04:30 PM
hierarchy system in mysql with php - by El Forum - 06-08-2009, 06:40 AM
hierarchy system in mysql with php - by El Forum - 06-08-2009, 09:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB