时时商务社区

标题: php从数据库查询结果生成树形列表的方法 [打印本页]

作者: xgnic    时间: 2018-2-14 05:46

            本文实例讲述了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实现多级分类生成树的方法示例
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2