Tree display category this post is finally edited by bing15 from 2013-02-02to retrieve data from the database, and displays the category in a tree, for example: & nbsp; announcement & nbsp; article & nbsp;-new article & nbs tree display category
At last, this post was edited by bing15 at 14:07:19 on to obtain data from the database and display the category in a tree. for example:
Announcement
Article
-New article
-Hot articles
The structure of the database category is:
Id, reid, topid, title
Id: Category id
Reid: parent class id
Topid: top-level id
Title: Name
Let me give you some data for convenience.
Id reid topid title
1 0 0 announcement
2 0 0 article
3 2 2 New articles
4 2 2 Hot articles
Remember: there may be a small category in the new article, which is an unlimited category.
------ Solution --------------------
$ Arr = array (
Array ('id' => 1, 'City _ name' => 'China', 'Rel _ id' => '1', 'Pi' => 0 ),
Array ('id' => 2, 'City _ name' => 'Guangdong ', 'Rel _ id' => '1-2 ', 'pid '=> 1 ),
Array ('id' => 3, 'City _ name' => 'Shenzhen ', 'Rel _ id' => '1-2-3 ', 'pid '=> 2 ),
Array ('id' => 4, 'City _ name' => 'Guangzhou ', 'Rel _ id' => '1-2-4', 'Pi' => 2)
);
Function find_subclass ($ pid ){
Global $ arr;
$ __Arr = array ();
Foreach ($ arr as $ k => $ v)
{
If ($ v ['pid '] ==$ pid) $ __arr [] = $ v;
}
Return $ __arr;
}
Function tree_subclass ($ pid = 0 ){
$ __Arr = array ();
$ __Arr = find_subclass ($ pid );
If (! Empty ($ __arr )){
Foreach ($ __arr as $ k => $ v)
{
$ __Arr [$ k] ['subclass '] = tree_subclass ($ v ['id']);
}
}
Return $ __arr;
}
Var_dump (tree_subclass (0 ));
?>
------ Solution --------------------
Reference:
How does my data recursively display subcategories under a category?
See http://bbs.csdn.net/topics/390364669