Infinitus China Ltd php Infinitus classification

Source: Internet
Author: User
Infinitus China Ltd.: Infinitus China Ltd. php Infinitus classification: Copy the code as follows: & lt ;? Php * class name: catalog function: unlimited classification class method: tree display category catalog_show ($ id) parameter $ id recursive call process: find all root categories whose parent category is 0-& gt; recursively retrieve all categories and display add category catalog_add ($ uid, $ 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 above introduces the Infinitus Chinese Company Limited php Infinitus classification, including the Infinitus Chinese company limited content, hope to be interested in PHP tutorials to help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.