Php code that uses recursive methods to implement unlimited classification
- $ Dbhost = "localhost"; // database host name
- $ Dbuser = "root"; // database username
- $ Dbpd = "123456"; // database password
- $ Dbname = "test"; // database name
- Mysql_connect ($ dbhost, $ dbuser, $ dbpd); // connect to the host
- Mysql_select_db ($ dbname); // select a database
- Mysql_query ("set names 'utf8 '");
- Display_tree ("primary", 0 );
- Function display_tree ($ tag, $ classid ){
- $ Result = mysql_query ("
- SELECT *
- FROM ylmf_class
- WHERE parentid = '". $ classid ."'
- ;"
- );
- While ($ row = mysql_fetch_array ($ result )){
- // Display the node name in indentation
- Echo $ tag. $ row ['classname']."
";
- // Call this function again to display the subnode of the subnode
- Display_tree ($ tag. "-rows", $ row ['id']);
- }
- }
- ?>
Remarks:The recursive method is used to reduce the efficiency of a large number of sub-columns. some mature cms systems use the method of producing arrays for calling to improve the efficiency. |