Home  >  Article  >  php教程  >  dedecms中,获取某一栏目所有子栏目

dedecms中,获取某一栏目所有子栏目

WBOY
WBOYOriginal
2016-06-13 09:35:061053browse

以前从来没写过递归(其实想想,对算法完全没概念),刚好有这个需求,试着写了一下,发现也挺容易的,特别记录一下。

数据库是dedecms默认的,dede_arctype是保存栏目的表,reid是栏目的父级栏目id。

<span><span>$array</span> = <span>array</span><span>();
get_sons(</span><span>$type</span>, <span>$array</span><span>);

</span><span>var_dump</span>(<span>$array</span><span>);

</span><span>function</span> get_sons(<span>$type</span>, &<span>$current_array</span><span>){
    </span><span>$result</span> = <span>mysql_query</span>("select id from dede_arctype where reid = {<span>$type</span>}"<span>);
    </span><span>while</span>(<span>$row</span> = <span>mysql_fetch_assoc</span>(<span>$result</span><span>)){
        </span><span>$current_array</span>[] = <span>$row</span>['id'<span>];
        get_sons(</span><span>$row</span>['id'], <span>$current_array</span><span>);
    }
}</span></span>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn