|
本文实例讲述了php从数据库查询结果生成树形列表的方法。分享给大家供大家参考。具体分析如下:
本代码可以从数据库读取数据生成一个类似于windows的资源管理器的树形列表
',
$parent, $showdepth > 0 ? 'show' : 'hide');
while (list($index, $node) = each($child_nodes[$parent])) {
for ($i = 0; $i %s
', -1, $name, 10);
if ($child_nodes[$node]) {
$newdepth = $showdepth;
if ($newdepth > 0) {
$newdepth--;
}
$new_ancestors = $ancestors;
$new_ancestors[] = $node;
display_directory($node, $newdepth, $new_ancestors);
}
}
print( "");
}
function setup_directory($parent, $maxdepth)
{
global $dirent_icons, $child_nodes, $node_data, $last_child;
$dirent_icons = sql_assoc('SELECT id,icon FROM dirent_types');
$query = 'SELECT id,parent,type,icon,name '.
'FROM directory '.
'ORDER BY parent,name';
$child_nodes = array();
$node_data = array();
$res = sql($query);
while (list($id,$parent,$type,$icon,$name)=db_fetch_row($res)){
$child_nodes[(int)$parent][] = $id;
$node_data[$id] = array( 'id' => $id,
'parent' => $parent,
'type' => $type,
'icon' => $icon,
'name' => $name);
$last_child[(int)$parent] = $id;
}
}
?>
希望本文所述对大家的php程序设计有所帮助。
您可能感兴趣的文章:PHP的开合式多级菜单程序用PHP实现多级树型菜单php创建多级目录代码php中设置多级目录session的问题php使用mkdir创建多级目录入门例子php创建多级目录的方法PHP超牛逼无限极分类生成树方法PHP生成树的方法PHP使用mkdir创建多级目录的方法PHP创建多级目录的两种方法PHP实现多级分类生成树的方法示例
|
|