Reprint, please indicate the author Surfchen and this page address http://www.yubeinet.com/Article.php?id=10 This article is mainly implemented by the Order By Sortlevel ..
Note: The following code only passes the function test, without passing the security test .. In practical use, please handle the data you want to join ... Prevent a hacker attack such as injection ..
Tony said nonsense ... huh ..look:
Build
Create Table Sort (ID INT (10) Unsigned Not Null Auto_Increment, / * Category ID * / SortName VARCHAR (20), / * Category * / Sortlevel Varchar (100), / * Classification Level * / Primary Key (ID)) Type = myisam
There are two PHP files .. One is a class file to operate the database .. One is an actual operation file ..
Class file:
Sort.class.php
php / ************************************************* Document Type: Class File function: Using the database to implement unlimited classification function Created by Surfchen, http: //yubeinet.com. ExamneverTeam ************************************** ************** / CLASS UNLIMITEDSORT {function unlimited 4 {$ this-> Table = 'sort'; // Table Name} / * Add sub-category * / Function AddSortByfatherId ($ Sortname $ fatherid) {$ fatherLevel = $ this-> getSortlevelByid ($ fatherid); // Get the parent rating IF ($ this-> CHECKIFNAMEXISTS ($ SortName, $ FATHERLEVEL) == true) {Return False; // This name has been Presented} $ sortlevel = $ this-> CreateSortlevel ($ FATHERLEVEL); // Construction class name $ query = "Insert Into {$ this-> Table} (SortName, Sortlevel) Values ('$ sortname",' $ sortlevel ') "; Echo $ query; if (mysql_query)) {return true;} echo 'new classification insert failed'; returnaf,} / * constructed a level name * / Function CreateSortlevel ($ FATHERLEVEL) { $ query = "SORTLEVEL) from sort where sortlevel} ___ '; $ results = mysql_query ($ query); $ row = mysql_fetch_array ($ result); if ($ row [0] == NULL) {Return $ FATHERLEVEL. '001'; $ SUBLVEL = SUBSTR ($ ROW [0] , -3); // Get the level name of the parent level is $ Num = $ SUBLEVEL; $ Num ; // The first few zero will remove for ($ I = 0; $ i <3; $ i ) ) {IF ($ SUBLEVEL {$ I}! = 0) {Break;} $ Num = '0'. $ Num; // Lost 0 When incremented 0 plus} returnid $ fatherLevel. $ Num;} / * Depending on the classification ID * / function GetSortlevelByid ($ ID) {$ query = "Select Sortlevel from {$ this-> table} where id = ID"; $ results = mysql_query ($ query); $ row = mysql_fetch_Array ($ RESULT); RETURN $ ROW [0];} / * Get the details of the classification * / function getsorts () {$ query = "Select * from {$ this-> table} Order by Sortlevel"; $ results = mysql_query ($ query); while ($ row =
MySQL_FETCH_ARRAY ($ Sorts) {$ sorts [] = $ row;} Return $ sorts;} / * Judgment subclass exists * / function checkifnameexists ($ SortName, $ FATHERLEVEL) {$ query = "Select Count (*) from Sort where sortlevel} ___ 'and sortname =' {$ SortName} '"; $ results = mysql_query ($ ruery); $ row = mysql_fetch_Array ($ results); if ($ row [0]> = 1 ) {echo 'name already exists'; return true;}}}?> actual operation file:
Sort.php
Please modify the following database information yourself..
php / ************************************************* Document type: execution File function: Using the database to implement unlimited classification function Created by Surfchen, http: //yubeinet.com. ExamneverTeam ************************************** ************** / include ('sort.class.php'); define ("Host", "); // Database Host Define (" User "," root ") ; // Database User Name Define ("pass", "); // Database pass code define (" db "," chenzecs "); // Database name mysql_connect (Host, user, pass); mysql_select_db (db); $ UnlimitedSort; if ($ _POST ['News ") {$ unlimitedsort-> addsortbyfatherid ($ _ post [' newsort '], $ _ post [' sort ']); // Add new classification} echo'