The above table structure
Write a supported class
<?
Class articletype extends comm {
Private $ article_type_id; // type ID
Private $ article_parent_id; // parent class ID
Private $ article_type_name; // type name
Private $ article_type_path; // path name
Private $ is_send_message;
Private $ is_hidden;
Private $ look_right;
Private $ model_type_id;
/*
Get... SET protocol initialization
*/
Function set_article_type_id ($ article_type_id) {$ this-> article_type_id = $ article_type_id ;}
Function get_article_type_id () {return $ this-> article_type_id ;}
Function set_article_parent_id ($ article_parent_id) {$ this-> article_parent_id = $ article_parent_id ;}
Function get_article_parent_id () {return $ this-> article_parent_id ;}
Function set_article_type_name ($ article_type_name) {$ this-> article_type_name = $ article_type_name ;}
Function get_article_type_name () {return $ this-> article_type_name ;}
Function set_article_type_path ($ article_type_path) {$ this-> article_type_path = $ article_type_path ;}
Function get_article_type_path () {return $ this-> article_type_path ;}
Function set_is_send_message ($ is_send_message) {$ this-> is_send_message = $ is_send_message ;}
Function get_is_send_message () {return $ this-> is_send_message ;}
Function set_is_hidden ($ is_hidden) {$ this-> is_hidden = $ is_hidden ;}
Function get_is_hidden () {return $ this-> is_hidden ;}
Function set_look_right ($ look_right) {$ this-> look_right = $ look_right ;}
Function get_look_right () {return $ this-> look_right ;}
Function set_model_type_id ($ model_type_id) {$ this-> model_type_id = $ model_type_id ;}
Function get_model_type_id () {return $ this-> model_type_id ;}
/*
Add_articletype;
*/
/*
List article categories
*/
Function list_articletype (){
Global $ dB;
Global $ article_type;
$ Re = $ db-> query ("select * From article_type order by article_type_path ");
// Echo "<SELECT> ";
While ($ r = $ db-> fetch_array ($ re )){
$ STR = "";
If (substr_count ($ R ['Article _ type_path '],', ')> 2 ){
$ STR = "| ";
For ($ I = 0; $ I <(substr_count ($ R ['Article _ type_path '],', ')-2); $ I ++ ){
$ Str. = "---";
}
}
// Echo "<option value = {$ R ['Article _ type_id ']}> ". $ Str. $ R ['Article _ type_name ']. "</option> ";
// Echo "<br> ";
$ STR = $ Str. $ R ['Article _ type_name '];
$ Article_type [] = array ('Article _ type_id '=> $ R ['Article _ type_id'], 'Article _ type_name '=> $ STR, 'Article _ parent_id '=> $ R ['Article _ parent_id'], 'Article _ type_path '=> $ R ['Article _ type_path']);
}
// Echo "</SELECT> ";
}
/*
Delete A category Function
*/
Function chk_del_article_type (){
Global $ dB;
$ SQL = "select article_parent_id from article_type where article_parent_id =". $ this-> get_article_type_id ();
$ Re = $ db-> query ($ SQL );
$ Num = $ db-> num_rows ($ re );
If ($ num> 0 ){
Echo "<SCRIPT> alert (/" also has a category. You must delete the category/") </SCRIPT> ";
Echo '<SCRIPT> window. Location = "javascript: history. Back (-1)" </SCRIPT> ';
Exit;
}
$ Sql1 = "delete from article_type where article_type_id =". $ this-> get_article_type_id ();
$ RT = $ db-> query ($ sql1 );
If ($ RT ){
Echo "<SCRIPT> alert (/" you deleted successfully/") </SCRIPT> ";
Echo '<SCRIPT> window. Location = "javascript: history. Back (-1)" </SCRIPT> ';
}
}
/*
Add parent class
*/
Function add_parent_type (){
Global $ dB;
/*
Generate SQL statements
*/
$ SQL = "insert into article_type (article_parent_id, article_type_name, is_send_message, is_hidden, look_right, model_type_id) values (". $ this-> get_article_parent_id (). ",'". $ this-> get_article_type_name (). "',". $ this-> get_is_send_message (). ",". $ this-> get_is_hidden (). ",". $ this-> get_look_right (). ",". $ this-> get_model_type_id (). ")";
Echo $ SQL;
$ Db-> query ($ SQL );
$ Id = $ db-> insert_id ();
$ SQL = "Update article_type set article_type_path = '". ",". $ id. ", 'where article_type_id =". $ ID;
$ Re = $ db-> query ($ SQL );
If ($ re ){
Parent: showmessage ("successful operation"); // call the comm Class Method
Parent: Jump ("right. php? Action = manage_news_type ");//
} Else {
$ SQL = "delete from article_type where article_type_id =". $ ID;
$ Db-> query ($ SQL );
Echo "<SCRIPT> alert (/" failed to insert data/") </SCRIPT> ";
Echo "<SCRIPT> location. href =/" right. php? Action = manage_news_type/"</SCRIPT> ";
}
}
/*
Add news subcategories
*/
Function add_child_type (){
Global $ dB;
/*
Generate SQL statements
*/
$ SQL = "insert into article_type (article_parent_id, article_type_name, is_send_message, is_hidden, look_right, model_type_id) values (". $ this-> get_article_parent_id (). ",'". $ this-> get_article_type_name (). "',". $ this-> get_is_send_message (). ",". $ this-> get_is_hidden (). ",". $ this-> get_look_right (). ",". $ this-> get_model_type_id (). ")";
Echo $ SQL;
$ Db-> query ($ SQL );
$ Id = $ db-> insert_id ();
/*
Query the path of the parent class contact
*/
$ Article_type_path = $ db-> Search ('Article _ type', 'Article _ type_path ', 'Article _ type_id = '. $ this-> get_article_type_id (), '2 ');
$ Path = $ article_type_path ['Article _ type_path ']. $ id .",";
$ SQL = "Update article_type set article_type_path = '". $ path. "'where article_type_id =". $ ID;
$ Re = $ db-> query ($ SQL );
If ($ re ){
Parent: showmessage ("successful operation"); // call the comm Class Method
Parent: Jump ("right. php? Action = manage_news_type ");//
} Else {
$ SQL = "delete from article_type where article_type_id =". $ ID;
$ Db-> query ($ SQL );
Echo "<SCRIPT> alert (/" failed to insert data/") </SCRIPT> ";
Echo "<SCRIPT> location. href =/" right. php? Action = manage_news_type/"</SCRIPT> ";
}
}
}
/*
Instantiate object
*/
$ Articletype = new articletype;
?>
Call Operations
<?
Case 'del _ article_type ':
$ Articletype-> set_article_type_id ($ array ['Article _ type_id ']);
$ Articletype-> chk_del_article_type ();
Break;
Case 'add _ parent_root ':
$ TP-> display('add_parent_root.htm ');
Break;
/*
Get form data and put it into an array, provide it to the class, and perform the warehouse receiving operation
*/
Case 'chk _ add_type ':
$ AR = array (
'Article _ type_name '= >$ _ post ['Article _ type_name'],
'Is _ send_message '= >$ _ post ['is _ send_message'],
Is _ den '=> $ _ post ['is _ den'],
'Look _ right' => $ _ post ['look _ right'],
'Model _ type_id '=> $ _ post ['model _ type_id'],
);
/*
Pass the set get Method to the class
*/
$ Articletype-> set_article_type_name ($ ar ['Article _ type_name ']);
$ Articletype-> set_article_parent_id (0 );
$ Articletype-> set_is_send_message ($ ar ['is _ send_message ']);
$ Articletype-> set_is_hidden ($ ar ['is _ hidden ']);
$ Articletype-> set_look_right ($ ar ['look _ right']);
$ Articletype-> set_model_type_id ($ ar ['model _ type_id ']);
$ Articletype-> add_parent_type ();
Break;
/*
Add sub-category
*/
If ($ action = 'chk _ add_child_type '){
$ AR = array (
'Article _ type_name '= >$ _ post ['Article _ type_name'],
'Is _ send_message '= >$ _ post ['is _ send_message'],
Is _ den '=> $ _ post ['is _ den'],
'Look _ right' => $ _ post ['look _ right'],
'Model _ type_id '=> $ _ post ['model _ type_id'],
'Article _ type_id '=> $ _ post ['Article _ type_id']
);
/*
Pass the set get Method to the class
*/
$ Articletype-> set_article_type_id ($ ar ['Article _ type_id ']);
$ Articletype-> set_article_type_name ($ ar ['Article _ type_name ']);
$ Articletype-> set_article_parent_id ($ article_type_id );
$ Articletype-> set_is_send_message ($ ar ['is _ send_message ']);
$ Articletype-> set_is_hidden ($ ar ['is _ hidden ']);
$ Articletype-> set_look_right ($ ar ['look _ right']);
$ Articletype-> set_model_type_id ($ ar ['model _ type_id ']);
$ Articletype-> add_child_type ();
}
?>