php代码如下://模拟数据库$data=array(array('id'=>1,'pid'=>0,'name'=>'栏目一'),array('id'=>2,'pid'=>1,'name'=>'子栏目'),array('id'=>3,'pid'=>1,'name'=>'二级栏目一'),array('id'=>4,'pid'=>3,'name'=>'三级栏目一'),array('id'=>5,'pid'=>4,'name'=>'四级栏目一'),array('id'=>6,'pid'=>0,'name'=>'一级栏目一'),array('id'=>7,'pid'=>2,'name'=>'一级栏目二'),array('id'=>8,'pid'=>1,'name'=>'二级栏目一'),array('id'=>9,'pid'=>2,'name'=>'三级栏目一'),array('id'=>10,'pid'=>3,'name'=>'四级栏目一'),);//转换数据$tree_data=array();foreach ($data as $key=>$value){$tree_data[$value['id']]=array('id'=>$value['id'],'parentid'=>$value['pid'],'name'=>$value['name']);}/*** 输出树形结构*/$tree=new Tree();$tree->init($tree_data);echo "<div class='tree well'>";echo $tree->get_treeview(0, $str);echo "</div>";
1 回答
海绵宝宝撒
TA贡献1809条经验 获得超8个赞
$query = "SELECT id,pid,name FROM tree ";
$tree_data=array();
if ($res=mysql_query($query)) while ($row=mysql_fetch_array($res)) $tree_data[]=$row;
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报
0/150
提交
取消