PHP无限分类分类导航LINK的代码

<?php 
       
    function getCatePath($cid,&$result=array()){
         include("conn.php");
         $sql="select * from list where id=$cid";
         $rs=mysqli_query($link,$sql);
         $row=mysqli_fetch_array($rs);
            if($row){
               $result[]=$row;
               getCatePath($row['pid'],$result);
            }
            krsort($result);
            return $result;
         }
         function displayCatePath($cid){
             $res=getCatePath($cid);
             $str='';
              foreach ($res as $key => $val) {
             $str.="<a href='cate.php?cid={$val['id']}'>{$val['catename']}</a>>";
                }
                return $str; 
         }
       echo  displayCatePath(10);

 

实现效果:

 

posted @ 2016-06-28 16:38  骏码信息  阅读(489)  评论(0编辑  收藏  举报