dedecms function share to get all subcolumns of a column

  • 2021-06-28 11:23:26
  • OfStack

Recursion has never been written before (in fact, I don't have any idea of the algorithm at all). Just in case of this need, try writing it once and it's easy to find, especially recording it once.

Database is dedecms default, dede_arctype is the table that holds the column, and reid is the parent column of the column, 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);
    }
}


Related articles: