Tree Display classification

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.