1.调用方法
function __construct(){
parent::__construct();
}
2.查出表名表中必须有名称,原来ID,父级ID
public function aaaa(){
$arr=$this->db->get("表名")->result_array();
$list['list']=$this->sel_dg($arr,$pid=0,$level=0);
$this->load->view("good/aaa",$list);
}
3.把查出来的数据进行循环
public function sel_dg($arr,$parent_id=0,$level=0){
static $data = array();
foreach($arr as $k=>$v) {
if($v['parent_id']==$parent_id){
$v['level']=$level;
$data[]=$v;
$this->sel_dg($arr,$v['cat_id'],$level+1);
}
}
return $data;
}
4.调到php页面进行输出
<?php echo str_repeat(' ',$v['level']);?>
<?php echo $v['cat_name']?>