考虑这种思路:
一个函数负责生成树型目录数组
然后直接显示这个数组的内容即可实际上,这种数据结构不好,如果在ORACLE中,可以考虑这种结构
本级机构ID 上级机构ID 机构其它信息
显示时用connect子句就可以了

解决方案 »

  1.   

    下面是我写的代码,存在问题,望高手帮忙改正...(感觉思路一开始就是错误的,呵呵)
    //树的生成算法(非递归算法)生成父节点$root_node;获得所有的对象列表$currentNode;for($i=0;$i<count($currentNode);){
            //获得当前对象$currentNode的父对象编码
            $fathercode=substr($currentNode[$i]['classcode'],0,(strlen($currentNode[$i]['classcode'])-3));
            if(父对象编码为空){
               //以$root_node为父节点生成该节点;
               $fatherNode=creatNode($text,$link,$currentNode,$root_node);    for($j=$i+1;$j<count($currentNode);$j++){
            $fatherCode=substr($currentNode[$j]['classcode'],0,(strlen($currentNode[$j]['classcode'])-3));
                    $len=strlen($fatherCode);
    if(strcmp(substr($currentNode[$j]['classcode'],0,$len),$fatherCode))==0){
          //保留父指针
          $nextNode=$fatherNode;
          //生成节点的指针
          $fatherNode=creatObj($text,$link,$childNode, $nextNode);
    }
    else{
        //如果不是是同级节点
        if(strlen($currentNode[$j]['classcode'])!=strlen($currentNode[$j-1]['classcode'])){
    $nextNode--;
        }
        else{  //同级节点
            $next=$fatherNode;
    $fatherNode(creatObj($text,$link,$childNode,$nextNode);
        } }
       }
            }
      

  2.   

    //树的生成算法(非递归算法)
    生成菜单对象$menu;//生成"权限管理"父节点;
    $topNode="node";
    $$topNode=&menu->additem($text,$link,$current_node);获得所有的对象列表$currentNode;for($i=0;$i<count($currentNode);$i++){
         $fathercode=substr($currentNode[$i]['classcode'],0,(strlen($currentNode[$i]['classcode'])-3));
         //计算父节点名称;
         $parnetNode=trim("node".$fathercode);
         $prefix_node="node".$current[$i]['classcode'];
         $$prefix_node=&$$parentNode->additem($text,$link,$currentNode);
    }