-
- $dbhost = "localhost"; // Database host name
- $dbuser = "root"; // Database user name
- $dbpd = "123456"; // Database password
- $dbname = "test"; //Database name
- mysql_connect($dbhost,$dbuser,$dbpd); //Connect to host
- mysql_select_db($dbname); //Select database
- mysql_query("SET NAMES 'utf8'");
- display_tree("├",0);
- function display_tree($tag,$classid) {
- $result = mysql_query("
- SELECT *
- FROM ylmf_class
- WHERE parentid = '" . $classid . "'
- ;"
- ) ;
- while ($row = mysql_fetch_array($result)) {
- //Indent the node name
- echo $tag.$row['classname'] . "
";
- //Call this again The function displays the child nodes of the child node
- display_tree($tag."─┴",$row['id']);
- }
- }
- ?>
Copy code
Remarks:Use recursion This method will be inefficient for a large number of sub-columns. Some mature CMS systems use the production array method to improve efficiency.
|