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

时间:2023-03-10 02:57:03
Dedecms 中,获取某一栏目所有子栏目

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

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

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