目录tree在页面上显示
//完整的目录结构 function get_dir_tree($uid,$from_dir=0){ $sql = "select dir_id,dir_name,depth,p_id from $this->_dir_table where user_id=$uid and is_del=0 and dir_id>=$from_dir"; $res = $this->db->query($sql)->result_array(); if(!isset($res[0])){ return null; } $this->load->helper('array'); //获取depth区间 $max_depth = 0; foreach($res as $dps => $d){ if($d['depth']>$max_depth){ $max_depth = $d['depth']; } } for($i=$max_depth;$i>=0;$i--){ //处理成树形,子集存在child里,有没有自己看有没有child字段 foreach($res as $key=>$val){ if($val['depth']==$i){ foreach($res as $k=>$v){ if($val['p_id']==$v['dir_id']){ $v['child'][] = $val; $res[$k] = $v; unset($res[$key]); } } } } } $return = $this->has_child_then_add_ul($res); $html="
- "; $html.=$return."
- ";
$ul_end = "
本文标题:目录tree在页面上显示
路径分享:http://azwzsj.com/article/pssooh.html