Home > php教程 > php手册 > body text

无限级别菜单的实现(其实还是有限级别的^0^)

WBOY
Release: 2016-06-21 09:11:37
Original
811 people have browsed it

菜单

  /* 看到很多朋友问过无限级别菜单的的问题(其实理论上还是有级别的,毕竟要受到个方便的条件的限制,比如: 数据库字段的类型等),我曾经用老大(唠叨)提供的代码写出来过无限级别的菜单,但是感觉效果不是很好(视觉上),于是趁着"夜深人静"就写这个"无限制级别的菜单",其实道理很简单,主要是数据表的设计,还有递归方法的使用(如果有时间我会用中值排序法来做),我会在下面给出数据结构的设计(非常简单),这里我没有加上竖直的虚线(windows资源管理器的虚线),同时Sql语句我也将其固定,大家可以根据自己的需要来修改!如果有问题可以联系我:msn:banneryue@sina.com,QQ:7665656,E_mail:yuepengfei@mail.banner.com.cn

明天(已经是今天了,呵呵)我会提供一个测试页面让大家来看(因为我在宿舍只能拨号上网,Ip地址不固定)

*/

/** 递归显示子节点函数
*
*
* @param $SearchPattern    查找的条件(like)
* @param $BaseNum 节点的层数
*/

           function ListChildTree($SearchPattern,$BaseNum){
               global $Tree;//声明连接数据库的句柄为全局
               $Sql="select DepartmentId,DepartmentName from test where DepartmentId like '$SearchPattern'";    //查找孩子节点
               $QueryChild=$Tree->query($Sql);          
               while($Result=$Tree->fetch_array($QueryChild)) { //取出孩子节点
                   $Space="";
                    for($j=0;$j                      $Space.="  ";                 //设置显示节点前面的距离,这里的空格的html被这里自动替换成"  "了
                   $ChildDepartment=trim($Result[0])."___";            
                   $ChildSql="select count(*) from test where DepartmentId like '$ChildDepartment'";//查找孩子节点的孩子节点
                   $ChildResult=$Tree->query_first($ChildSql);             
                   $TableId="ta".trim($Result[0]); //设置表格Id
                   $TablePic="ta".trim($Result[0])."pic";    //设置图片Id                   
                   if($ChildResult[0]                      ?>
                    

=$Space?>无限级别菜单的实现(其实还是有限级别的^0^)=$Result[1]?>
                    
                
                 }else{           //找到则显示"+"图片            
                  ?>
                   
=$Space?>无限级别菜单的实现(其实还是有限级别的^0^)=$Result[1]?>
                  
            
              ListChildTree($ChildDepartment,$BaseNum);//递归调用函数本身来显示其他孩子节点
            }//end if?>
             

            }//end while
           }//end function?>


无限级菜单测试


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!