首页  >  文章  >  后端开发  >  dedecms中,获取某一栏目所有子栏目_PHP教程

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

WBOY
WBOY原创
2016-07-13 10:29:42932浏览

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

数据库是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>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/770662.htmlTechArticle以前从来没写过递归(其实想想,对算法完全没概念),刚好有这个需求,试着写了一下,发现也挺容易的,特别记录一下。 数据库是de...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn