Home > Backend Development > PHP Tutorial > In dedecms, get all sub-columns of a certain column_PHP tutorial

In dedecms, get all sub-columns of a certain column_PHP tutorial

WBOY
Release: 2016-07-13 10:29:42
Original
954 people have browsed it

I have never written recursion before (actually, thinking about it, I have no idea about algorithms at all). I happened to have this need, so I tried to write it and found that it is quite easy. I will record it in particular.

The database is dedecms default, dede_arctype is the table that saves the column, and reid is the parent column id of the column.

<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>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/770662.htmlTechArticleI have never written recursion before (actually, think about it, I have no idea about algorithms at all). I happen to have this need. Try it. After writing it down, I found that it was quite easy, so I made a special note of it. The database is de...
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template