PHP uses recursive method to implement infinite class classification code

Source: Internet
Author: User
    1. $dbhost = "localhost"; Database host Name
    2. $dbuser = "root"; Database user Name
    3. $DBPD = "123456"; Database Password
    4. $dbname = "Test"; Database name
    5. Mysql_connect ($dbhost, $dbuser, $DBPD); Connecting the host
    6. mysql_select_db ($dbname); Select Database
    7. mysql_query ("SET NAMES ' UTF8 '");
    8. Display_tree ("├", 0);
    9. function Display_tree ($tag, $classid) {
    10. $result = mysql_query ("
    11. SELECT *
    12. From Ylmf_class
    13. WHERE parentid = ' ". $classid. "'
    14. ;"
    15. );
    16. while ($row = Mysql_fetch_array ($result)) {
    17. Indent Display node name
    18. echo $tag. $row [' classname ']. "
      ";
    19. Call this function again to show child nodes of child nodes
    20. Display_tree ($tag. " ─┴ ", $row [' id ']);
    21. }
    22. }
    23. ?>
Copy Code

Note : The use of recursive method, for a large number of sub-column efficiency will be low, some mature CMS system, are used in the production of an array of methods called to improve efficiency.

  • 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.