PHP code: // unlimited classification-path // principle: splits the path to obtain all desired PIDs and IDs. The path is a field in the design table, contains a series of IDs from the ancestor id to the parent id // This method, whether viewed or deleted or other operations, you only need to execute an SQL statement once to achieve the desired results. // This method is also preferred, because my principle is that recursion is not used, instead of recursion $ link = mysql_connect ('localhost', 'username, 'Password'); if (mysql_errno () {echo 'database Connection Failed :'. mysql_error ();} mysql_select_db ('db _ kind'); mysql_set_charset ('utf8'); // concat (), concatenate a string into a new string // the following code completes an infinite classification of reality $ SQL = "select concat (path, '-', Id) as conpath, id, name, path from wx_kind order by conpath "; $ result = mysql_query ($ SQL ); while ($ row = mysql_fetch_assoc ($ result) {$ arr = array (); // you can select the path field or the new conpath field to split the string. // note one point for the explode () function, no matter whether the string to be split contains any character that uses the parameter, at least one array containing an element $ count = count (explode ('-', $ row ['path']) is returned. -1; // str_repeat (), repeat the string mainly for the sake of clear format $ str = str_repeat ('', $ count); echo $ str. $ id. '=> '. $ row ['name']. '