开发者

having small problem wth this ci navigation script

my controller is

[code]$data['navlist'] = $this->MCats->getCategoriesNav();[/code]

model is

[code]
    function getCategoriesNav(){
        $data = array();
        $this->db->group_by('parentid', 'id');
        $Q = $this->db->get('categories');
        if($Q->num_rows >0){
            foreach($Q->result() as $row){
                if($row-开发者_Go百科>parentid > 0){
                    $data[0][$row->parentid]['children'][$row->id] = $row->name;
                }else{
                $data[0][$row->id]['name'] = $row->name;
                }
            }
        }
        $Q->free_result();
        return $data;
    }
[/code]

and views is

[code]if(count($navlist)){
    echo "<ul>";
    foreach($navlist as $key => $list){
        foreach($list as $topkey => $toplist){
            echo "<li class='cat'>";
            echo anchor("welcome/cat/$topkey", $toplist);
            echo "</li>\n";
            if(count($toplist['children'])){
            foreach($toplist['children'] as $subkey => $subname){
                echo "\n<li class='subcat'>";
                echo anchor("welcome/cat/$subkey", $subname);
                echo "</li>";
                }
            }
        }

    }
    echo "</ul>\n";

}[/code]

i am not getting category name for top menu, please help me on this,


It looks like your $data[0] used on two different places should be $data instead, You are loading all the looped db results into one array key, key 0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜