Welcome Guest, Not a member yet? Register   Sign In
creating category tree array
#2

[eluser]WanWizard[/eluser]
From the top of my head:
Code:
function build_child($old_id)
{
    $result = array();

    $children = $this->category_model->get_subcategories(array('category_id' => $old_id));

    foreach ($children as $child)
    {
        $id = $child->id_cat;

        $result[$id] = $child;
        
        $children = $this->build_child($child->id_subcat);
        
        if ( count($children) )
        {
            $result[$id]['subcategs'] = $children;
        }
    }
    
    return $result;
}

function get_tree_by_category_alias($alias = FALSE)
{
    if ( ! $alias)
    {
        return FALSE;
    }
        
    $this->load->model('category_model');

    $left_category = $this->category_model->get_categories(array('alias' => $alias));

    return $this->build_child($left_category->id_cat);
}


Messages In This Thread
creating category tree array - by El Forum - 06-16-2010, 10:23 AM
creating category tree array - by El Forum - 06-16-2010, 11:56 AM
creating category tree array - by El Forum - 06-16-2010, 12:38 PM
creating category tree array - by El Forum - 02-12-2012, 09:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB