PHP树的代码,可以嵌套任意层


Posted in PHP onOctober 09, 2006

PHP树的代码,可以嵌套任意层 <?
file://建立树的主要函数,传递的参数为根节点的编号和根节点的标题
function create_tree($rootid,$roottilte){
  print_parent_from_rootsortid($rootid,$roottilte);
}
file://打印根节点div头的函数
function print_parent_from_rootsortid($rootid,$roottilte){
  $parent_fullname="R".$rootid."Parent";                      file://div 父级区别标志
  $parent_id="R".$rootid;
  $parent_pic="R".$rootid."img";
  echo "
      <DIV class=parent id=$parent_fullname><A
      href=\"http://www.csdn.net/expert/menu.shtm#\"
      onclick=\"expandIt('$parent_id'); return false\"><IMG border=0 height=13 id=$parent_pic
      src=\"image/folderclosed000.gif\" width=19>$roottilte</A></DIV>";

  global $cursor_tree;
  $Bottom_Flag=0;
  $len=strlen($rootid)+2;      file://子级编码为父级编码长度加2
  $query = "SELECT ResourceSortNo,ResourceSortName,SectionBottomFlag
            From TbSort
            Where length(ResourceSortNo)=$len and ResourceSortNo like '$rootid%'";            file://sql查询语句
  ora_parse($cursor_tree, $query) or die;
  ora_exec($cursor_tree);

  $child_fullname="R".$rootid."Child";                     file://div 子级区别标志
  echo "<DIV class=child id=$child_fullname>";             file://打印一个div子级头
  while(ora_fetch($cursor_tree)){
    $Sort_No  = trim(ora_getcolumn($cursor_tree,0));
    $Sort_Title = trim(ora_getcolumn($cursor_tree,1));
    $Bottom_Flag  = trim(ora_getcolumn($cursor_tree,2));
    print_child_from_rootsortid($Sort_Title,$Sort_No, $Bottom_Flag);           file://循环调用打印子级编码函数
  }
  echo "</DIV>";

}
file://判断是否是末级标志,并且打印子级编码的函数
function print_child_from_rootsortid($Section_Title,$Section_No,$Bottom_Flag){
  global $num;
  $len=2*$num+2;
  for($j=0;$j<$len;$j++){
    echo " ";
  }                                                                   file://输出节点之间间距空格的循环

  if($Bottom_Flag==1){
    echo "
    <IMG border=0 height=13 src=\"image/folderclosed000.gif\" width=19>
    <A href=\"http://www.csdn.net/expert/exchange.asp\" target=forum>$Section_Title</A><BR>";
  }else{
    $p_id="R".$Section_No;
    $p_pic="R".$Section_No."img";
    echo "
    <IMG border=0 height=13 id=$p_pic src=\"image/folderclosed000.gif\" width=19>
    <A href=\"http://www.csdn.net/expert/exchange.asp\" onclick=\"expandIt('$p_id'); return false\">$Section_Title</A><BR>";
    $child_fullname="R".$Section_No."Child";
    echo "<DIV class=child id=$child_fullname>";                     file://打印div子标志头
    find_allchild_from_rootsortid($Section_No);                      file://查找子级别内容-----嵌套递归函数甲
    echo "</DIV>";                                                   file://打印div子标尾部

  }

}
file://查询所有子级编码的函数
function find_allchild_from_rootsortid($Section_No){
  global $handle,$num;
  $num++;
  $cursor_ary[$num] = ora_open($handle);
  $len=strlen($Section_No)+2;      file://μ?μ?×ó??±e±ào?3¤?è
  $query = "SELECT ResourceSortNo,ResourceSortName,SectionBottomFlag
            From TbSort
            Where length(ResourceSortNo)=$len and ResourceSortNo like '$rootid%'";            file://sql查询语句
  ora_parse($cursor_ary[$num], $query) or die;
  ora_exec($cursor_ary[$num]);
  while(ora_fetch($cursor_ary[$num]))
  {
    $Sort_Title = trim(ora_getcolumn($cursor_ary[$num],1));
    $Sort_No  = trim(ora_getcolumn($cursor_ary[$num],0));
    $Bottom_Flag  = trim(ora_getcolumn($cursor_ary[$num],2));
    print_child_from_rootsortid($Sort_Title,$Sort_No,$Bottom_Flag);       file://打印所有的子级节点-----嵌套递归函数乙
  }
  $num--;
}

?>

PHP 相关文章推荐
PHP通用检测函数集合
Nov 25 PHP
FCKeditor添加自定义按钮
Mar 27 PHP
php 字符转义 注意事项
May 27 PHP
探讨如何在php168_cms中提取验证码
Jun 08 PHP
浅析php插件 HTMLPurifier HTML解析器
Jul 01 PHP
PHP开发微信支付的代码分享
May 25 PHP
php版微信数据统计接口用法示例
Oct 12 PHP
实例讲解YII2中多表关联的使用方法
Jul 21 PHP
基于PHP实现栈数据结构和括号匹配算法示例
Aug 10 PHP
PHP简单实现正则匹配省市区的方法
Apr 13 PHP
PHP进阶学习之命名空间基本用法分析
Jun 18 PHP
php项目中类的自动加载实例讲解
Sep 12 PHP
PHP中的超全局变量
Oct 09 #PHP
我常用的几个类
Oct 09 #PHP
多文件上传的例子
Oct 09 #PHP
PHP4(windows版本)中的COM函数
Oct 09 #PHP
实现树状结构的两种方法
Oct 09 #PHP
PHP邮件专题
Oct 09 #PHP
Content-type 的说明
Oct 09 #PHP
You might like
受疫情影响 动画《Re从零开始的异世界生活》第二季延期至7月
2020/03/10 日漫
PHP URL路由类实例
2013/11/12 PHP
php事务处理实例详解
2014/07/11 PHP
PHP的Yii框架中Model模型的学习教程
2016/03/29 PHP
PHP HTTP 认证实例详解
2016/11/03 PHP
自动生成文章摘要的代码[JavaScript 版本]
2007/03/20 Javascript
javascript中兼容主流浏览器的动态生成iframe方法
2014/05/05 Javascript
javascript获取元素离文档各边距离的方法
2015/02/13 Javascript
jquery层级选择器的实现(匹配后代元素div)
2016/09/05 Javascript
JS中使用正则表达式g模式和非g模式的区别
2017/04/01 Javascript
vue组件实现可搜索下拉框扩展
2020/10/23 Javascript
JavaScript强制类型转换和隐式类型转换操作示例
2019/05/01 Javascript
VUE脚手架具体使用方法
2019/05/20 Javascript
jQuery层叠选择器用法实例分析
2019/06/28 jQuery
vue中对象数组去重的实现
2020/02/06 Javascript
[04:29]2014DOTA2国际邀请赛 主赛事第三日TOPPLAY
2014/07/21 DOTA
python解析模块(ConfigParser)使用方法
2013/12/10 Python
Python字符串处理之count()方法的使用
2015/05/18 Python
Python3实现将文件树中所有文件和子目录归档到tar压缩文件的方法
2015/05/22 Python
解决Python 遍历字典时删除元素报异常的问题
2016/09/11 Python
python字典多键值及重复键值的使用方法(详解)
2016/10/31 Python
分享几道你可能遇到的python面试题
2017/07/24 Python
Python3 模块、包调用&amp;路径详解
2017/10/25 Python
django2+uwsgi+nginx上线部署到服务器Ubuntu16.04
2018/06/26 Python
对numpy数据写入文件的方法讲解
2018/07/09 Python
jupyter notebook 中输出pyecharts图实例
2020/04/23 Python
Html5无刷新修改browser Url的方法
2014/01/15 HTML / CSS
AmazeUI中各种的导航式菜单与解决方法
2020/08/19 HTML / CSS
智能钱包:Ekster
2019/11/21 全球购物
上学迟到的检讨书
2014/01/11 职场文书
《曹刿论战》教学反思
2014/03/02 职场文书
企业承诺书格式
2014/05/21 职场文书
退伍军人感言
2015/08/01 职场文书
Html5获取用户当前位置的几种方式
2022/01/18 HTML / CSS
Nginx禁止ip访问或非法域名访问
2022/04/07 Servers
Rust中的Struct使用示例详解
2022/08/14 Javascript