有源码下载吗

来源:4-1 php无限分类分类导航LINK的代码实现

weixin_慕瓜6241313

2016-12-25 19:35

求下载地址

写回答 关注

1回答

  • hey_whatsup
    2016-12-28 17:00:31

    <?php


    function getList($pid=0,&$res=array(),$spac=0){

    $spac=$spac+4;

    $link=mysqli_connect('localhost','root','root') or die('没有链接到服务器');

        mysqli_select_db($link,'deepcate') or die("没有链接到表");

    $sql="select * from cate where pid={$pid}";

    $rows=mysqli_query($link, $sql);

    if($rows){

         while($row=mysqli_fetch_assoc($rows)){

          $row['catename']=str_repeat('&nbsp;',$spac).'|--'.$row['catename']; 

          $res[]=$row;

    getList($row['id'],$res,$spac);

        }

    return $res;

    }

    }


    function showList($pid=0,$select){

    $result=getList($pid);

    echo "<select name='cate'>";

    foreach ($result as $key => $value) {

    $selecstr='';

    if($value['id']==$select){

    $selectstr='selected';

    }

     echo "<option  {$selectstr} >{$value['catename']}</option>";

    }

    }



    function getCatePath($id,&$res=array(),$spac=0){

    $spac=1;

    $link=mysqli_connect('localhost','root','root') or die('没有链接到服务器');

        mysqli_select_db($link,'deepcate') or die("没有链接到表");

    $sql="select * from cate where id={$id}";

    $rows= mysqli_query($link, $sql);

    if($rows){

    while($row=mysqli_fetch_assoc($rows)){

    $row['catename']=$row['catename'].str_repeat('>',$spac);

    $res[]=$row;

    getCatePath($row['pid'],$res,$spac);

    }

    krsort($res);

    return $res;

    }

    }


    function showCatePath($id){

    $res=getCatePath($id);

    foreach ($res as $key => $value) {

    echo "<a href='cate.php?cid={$value['id']}'>{$value['catename']}</a>";

    }

    }

    showCatePath(10);

    ?>

    纯自写<--!>

PHP无限级分类技术

经典的递归实现和全路径实现两种方式实现无限分类

30088 学习 · 84 问题

查看课程

相似问题