Tree-type Display classification
This post was last edited by bing15 on 2013-02-02 14:07:19
Get the data from the database and display the classification in tree form, such as:
Notice
Article
-New articles
-Hot Articles
The structure of the taxonomy database is:
Id,reid,topid,title
ID: Category ID
Reid: Parent class ID
TOPID: Top ID
Title: Name
Let me give you a little bit of data, which is easier to do.
ID Reid topid Title
1 0 0 Announcements
2 0 0 Articles
3 2 2 new articles
4 2 2 hot Articles
Remember: There may be a small category in the new article, Oh, Infinite class classification.
------Solution--------------------
$arr = Array (
Array (' ID ' =>1, ' city_name ' = ' China ', ' rel_id ' = ' 1 ', ' pid ' =>0),
Array (' ID ' =>2, ' city_name ' = ' Guangdong ', ' rel_id ' = ' 1-2 ', ' pid ' =>1),
The array (' ID ' =>3, ' city_name ' = ' Shenzhen ', ' rel_id ' and ' I ', ' pid ' =>2),
Array (' ID ' =>4, ' city_name ' = ' guangzhou ', ' rel_id ' = ' 1-2-4 ', ' pid ' =>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 sub-categories under classification?
See http://bbs.csdn.net/topics/390364669