Php Infinitus classification. Copy the code as follows :? Php * class name: catalog function: unlimited classification class method: tree display category catalog_show ($ id) parameter
The code is as follows:
/* ===================================================== ============================
Class name: catalog
Function: unlimited classification
Method:
Tree display category
Catalog_show ($ id) // recursively calls the parameter $ id
Process: find all root categories whose parent category is 0-> recursively retrieve all categories and display them
Add category
Catalog_add ($ uid, $ name) // $ uid parent id // $ name category name
Process: add a new sub-id under this id based on $ uid
Delete Category
Catalog_del ($ uid) // parameter $ uid number category to be deleted
Modify category
Catalog_set ($ id, $ name) // parameter $ id the category to be modified // The new category name of the parameter $ name
Variable:
$ Config // database information-> host, user, pass, dbname
$ Catalog_dbname // category database name
Database:
Catalog_id // the natural sequence number of the category
Catalog_uid // parent category of the category
Catalog_name // category name
Catalog_path_number // kinship tree Number format
Catalog_path_char // kinship tree character format classification 1: Classification 1.1: Classification 1.1.1
Reference http://www.phpchina.com/12823/viewspace_4468.html
========================================================== ========================= */
Class catalog {
Var $ config;
Var $ catalog_dbname;
Var $ links;
Private function connect (){
$ This-> links = mysql_connect ($ this-> config ['host'], $ this-> config ['user'], $ this-> config ['pass']) or die ("Error: Nth ". _ LINE __. "line
". Mysql_error ());
Mysql_select_db ($ this-> config ['dbname'], $ this-> links );
Mysql_query ("set names gb2312 ");
}
Function catalog_show ($ uid = 0 ){
$ This-> connect ();
$ SQL = "Select * FROM". $ this-> catalog_dbname ."
Where catalog_uid = ". $ uid ."
OrDER BY catalog_id ";
$ Result = mysql_query ($ SQL, $ this-> links) or die ("Error: LINE". _ LINE _."
". Mysql_error ());
If (mysql_num_rows ($ result)> 0 ){
While ($ row = mysql_fetch_assoc ($ result )){
If ($ this-> sun_catalog ($ row ['catalog _ id']) {// determines whether a subcategory exists.
$ Cata_img = "";
} Else {
$ Cata_img = "";
}
$ Path = explode (":", $ row ['catalog _ path_number ']);
If (count ($ path)> 1 ){
For ($ I = 1; $ I $ Path_img. = "";
}
}
Echo $ path_img. $ cata_img;
Echo "";
Echo $ row ['catalog _ name']."
";
$ Path_img = "";
If ($ this-> sun_catalog ($ row ['catalog _ id']) {
$ Hidden_p = "style = 'display: none '";
Echo"
";
$ This-> catalog_show ($ row ['catalog _ id']);
Echo"
";
}
}
}
}
Private function sun_catalog ($ uid) {// determines whether a subcategory exists.
$ SQL = "Select * FROM". $ this-> catalog_dbname ."
Where catalog_uid = ". $ uid ."
OrDER BY catalog_id ";
$ Result = mysql_query ($ SQL, $ this-> links) or die ("Error: LINE". _ LINE _."
". Mysql_error ());
If (mysql_num_rows ($ result)> 0 ){
Return true;
} Else {
Return false;
}
}
Function catalog_add ($ uid, $ name ){
// Obtain the kinship tree of the parent id
$ This-> connect ();
$ SQL = "Select * FROM". $ this-> catalog_dbname ."
Where catalog_id = '". $ uid ."'";
$ Result = mysql_query ($ SQL, $ this-> links)
Or die ("Error: row". _ LINE _."
". Mysql_error ());
$ Row = mysql_fetch_assoc ($ result );
$ Fid_path_number = $ row ['catalog _ path_number ']; // id of the digit family tree
$ Fid_path_char = $ row ['catalog _ path_char ']; // id of the character family tree
// Insert data into the row first-> Find the latest inserted id, and modify it based on this id.
$ SQL = "Insert INTO". $ this-> catalog_dbname. "(catalog_uid, catalog_name)
VALUES (". $ uid.", '". $ name ."')";
$ Result = mysql_query ($ SQL, $ this-> links)
Or die ("Error: row". _ LINE _."
". Mysql_error ());
$ Catalog_id = mysql_insert_id (); // Obtain your own id
$ Catalog_path_number = $ fid_path_number. ":". $ catalog_id; // Obtain the number of your own kinship.
$ Catalog_path_char = $ fid_path_char. ":". $ name; // Get your own character kinship
$ SQL = "update'". $ this-> catalog_dbname ."'
SET
Catalog_path_number = '". $ catalog_path_number ."',
Catalog_path_char = '". $ catalog_path_char ."'
Where
Catalog_id = ". $ catalog_id;
Mysql_query ($ SQL, $ this-> links)
Or die ("Error: row". _ LINE _."
". Mysql_error ());
}
Function catalog_del ($ id ){
$ This-> connect ();
$ SQL = "Delete FROM". $ this-> catalog_dbname ."
Where catalog_id = ". $ id;
Mysql_query ($ SQL, $ this-> links)
Or die ("Error: row". _ LINE _."
". Mysql_error ());
}
Function catalog_set ($ id, $ name ){
$ This-> connect ();
$ SQL = "Update". $ this-> catalog_dbname ."
SET
Catalog_name = '". $ name ."'
Where
Catalog_id = ". $ id;
Mysql_query ($ SQL, $ this-> links)
Or die ("Error: row". _ LINE _."
". Mysql_error ());
}
}
?>
The http://www.bkjia.com/PHPjc/318618.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318618.htmlTechArticle code is as follows :? Php/* = ============================ class name: catg_function: unlimited classification class method: tree display category catalog_show ($ id) // parameter...