首页  >  文章  >  后端开发  >  php如何实现全路径无限分类导航(代码)

php如何实现全路径无限分类导航(代码)

不言
不言转载
2018-10-09 14:06:263151浏览

本篇文章给大家带来的内容是关于php如何实现全路径无限分类导航(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

<?php

/**
 * @param php全路径无限分类
 */

include(&#39;db.inc.php&#39;);
function getPathCate($cateid){
    $sql = "select * ,concat(path,&#39;,&#39;,id) fullpath from likecate where id = $cateid";
    $res = mysql_query($sql);
    $row = mysql_fetch_assoc($res);
    $ids = $row[&#39;fullpath&#39;];
    $sql = "select * from likecate where id in ($ids) orders by id asc";
    $res = mysql_query($sql);
    $result = array();
    while ($row = mysql_fetch_assoc($res)) {
        $result[] = $row;
    }
    return $result;
}

function displayPath($cateid,$link=&#39;cate.php?cid=&#39;){
    $res = getPathCate($cateid);
    $str = &#39;&#39;;
    foreach ($res as $key => $value) {
        $str .= "<a href =&#39;{$link}{$value[&#39;id&#39;]}&#39;>{$value[&#39;catename&#39;]}</a>";
    }

}

echo displayPath(4,&#39;cate.php?p=1&cid=&#39;);

以上是php如何实现全路径无限分类导航(代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:cnblogs.com。如有侵权,请联系admin@php.cn删除