PHP / * CREATE TABLE `category` (` categoryID` int (10) unsigned NOT NULL auto_increment, `categoryParentID` int (10) unsigned NOT NULL default '0',` categoryName` varchar (50) NOT NULL default '' , Key `Cate_ID` (` CategoryID`)) Type = myisam auto_increment = 11; ## Export table in the table in the table` # Insert Into `Category` Values (1, 0, 'first class category 1'); Insert Into `category` Values (2, 1, 'second class category 1'); Insert INTO` Category` Values (3, 1, 'Second Category 2'); Insert Into `Category` Values (4, 1, ' Category 3 '); Insert Into `Category` VALUES (5, 2,' 3 Category 21 '); Insert Into` Category` Values (6, 2,' 3 Category 22 '); Insert Into `Category` Values 7, 2, 'Three Category 23'); Insert Into `Category` Values (8, 3, 'RFWESDFSD'); Insert Into` Category` Values (9, 4, '54534w43'); Insert Into `Category` VALUES (10, 5, '66666'); If you have any questions, please don't ask me. Other OK. Welcome to modify use. This is simple.
* / mysql_connect ("localhost", 'root', ''); mysql_select_db ("test"); $ cate_table = "category"; function _getcategory ($ category_id = 0, $ depth = 1) {Global $ cate_table; $ sql = "SELECT * FROM $ cate_table ORDER BY categoryID DESC"; $ result = mysql_query ($ sql); while ($ row = mysql_fetch_array ($ result)) {$ array [$ row [categoryParentID]] [$ row [categoryID]] = array ('id' => $ row [categoryid], 'parent' => $ row [categoryParentID], 'name' => $ row [categoryName]);} f (! isset ($ array [$ category_id]) "{Return" ";} foreach ($ array [$ category_id] AS $ key => $ category) {echo"