当前位置:编程学习 > php >>

php无限分类读取多级菜单

//数据库表

 \

 

<?php 
include "comm.php"; 
 
//获取分类菜单  
 
$arr=getTree(); 
$arrone=getFlone(59); 
$arrtwo=getFltwo(93); 
$arrmenu=getFlmenu(59); 
print_r($arrmenu); 
 
 
//获取分类树  
function getTree(){ 
    global $db; 
    $sql="select flid,flpid,flpath,fltitle,fldes,keyword from fenlei order by flid"; 
    $rs=$db->query($sql); 
    $data=array(); 
    while ($row=$db->fetch_array($rs)){ 
        $data[]=$row; 
    } 
    return $data; 

//活动一级分类 注意在这顶级分类id为 59  
function getFlone($flpid){ 
    global $db; 
    $sql="select * from fenlei where flpid={$flpid} order by flid"; 
    $rs=$db->query($sql); 
    $data=array(); 
    while ($row=$db->fetch_array($rs)){ 
        $data[]=$row; 
    } 
    return $data; 

//活动二级分类  
function getFltwo($flpid){ 
    global $db; 
    $sql="select * from fenlei where flpid={$flpid} order by flid"; 
    $rs=$db->query($sql); 
    $data=array(); 
    while ($row=$db->fetch_array($rs)){ 
        $data[]=$row; 
    } 
    return $data; 

//循环获取菜单,此数据库顶级父分类id为 59   
function getFlmenu($flpid){ 
    global $db; 
    $arr=getFlone($flpid); 
 
    foreach ($arr as &$v) { 
        $arrt=getFlone($v['flid']); 
         
      foreach ($arrt as &$vl){ 
        $arrtt=getFlone($vl['flid']); 
        $vl['tt']=$arrtt; 
      } 
        $v['two']=$arrt; 
    } 
    return $arr; 

 
?> 
<?php
include "comm.php";

//获取分类菜单

$arr=getTree();
$arrone=getFlone(59);
$arrtwo=getFltwo(93);
$arrmenu=getFlmenu(59);
print_r($arrmenu);


//获取分类树 www.zzzyk.com
function getTree(){
 global $db;
 $sql="select flid,flpid,flpath,fltitle,fldes,keyword from fenlei order by flid";
 $rs=$db->query($sql);
 $data=array();
 while ($row=$db->fetch_array($rs)){
  $data[]=$row;
 }
 return $data;
}
//活动一级分类 注意在这顶级分类id为 59
function getFlone($flpid){
 global $db;
 $sql="select * from fenlei where flpid={$flpid} order by flid";
 $rs=$db->query($sql);
 $data=array();
 while ($row=$db->fetch_array($rs)){
  $data[]=$row;
 }
 return $data;
}
//活动二级分类
function getFltwo($flpid){
 global $db;
 $sql="select * from fenlei where flpid={$flpid} order by flid";
 $rs=$db->query($sql);
 $data=array();
 while ($row=$db->fetch_array($rs)){
  $data[]=$row;
 }
 return $data;
}
//循环获取菜单,此数据库顶级父分类id为 59
function getFlmenu($flpid){
 global $db;
 $arr=getFlone($flpid);

 foreach ($arr as &$v) {
  $arrt=getFlone($v['flid']);
  
   foreach ($arrt as &$vl){
    $arrtt=getFlone($vl['flid']);
    $vl['tt']=$arrtt;
   }
   $v['two']=$arrt;
 }
 return $arr;
}

?>

 

[php] <pre> 
<pre>[html] Array 

    [0] => Array 
        ( 
            [0] => 93 
            [flid] => 93 
            [1] => 59 
            [flpid] => 59 
            [2] => 国内新闻 
            [fltitle] => 国内新闻 
            [3] => 0-59 
            [flpath] => 0-59 
            [4] => 国内新闻 
            [fldes] => 国内新闻 
            [5] => 国内新闻 
            [keyword] => 国内新闻 
            [two] => Array 
                ( 
                    [0] => Array 
                        ( 
                            [0] => 98 
                            [flid] => 98 
                            [1] => 93 
                            [flpid] => 93 
                            [2] => 时政 
                            [fltitle] => 时政 
         &

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,