Home  >  Article  >  Backend Development  >  How to implement full-path unlimited category navigation in PHP (code)

How to implement full-path unlimited category navigation in PHP (code)

不言
不言forward
2018-10-09 14:06:263150browse

The content of this article is about how to implement full-path unlimited classification navigation (code) in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<?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;);

The above is the detailed content of How to implement full-path unlimited category navigation in PHP (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete