Php tree structure operation code (14 ). Tree structure is used by many program members. the preceding tree structure operation class can solve this problem well. Php Tutorial tree structure operation class code ************* tree structure is used by many program members. the above section describes tree structure operation classes, this problem is well solved.
/Php Tutorial tree structure operation class code
/*************************************** ************************
* Tree structure operation class (ideal for writing stored procedures)
*
**************************************** ************************/
Class treenode {
Var $ f_id = 'id ';
Var $ f_pid = 'pid ';
Var $ f_lft = 'lft ';
Var $ f_rgt = 'rgt ';
Var $ f_s = 'sequence ';
Var $ f_level = 'lev ';
Var $ f_child_num = 'child _ num ';
Var $ table;
Var $ db;
/**
* Constructor
* @ Param string $ table name
* @ Param object $ dbhanle adodb database tutorial operation handle
*/
Function treenode ($ table, $ dbhandle ){
$ This-> db = $ dbhandle;
$ This-> table = $ table;
// $ This-> db-> debug = true;
}
/**
* Add a subnode
* @ Param array $ data node data
* @ Return bool
*/
Function addchild ($ data ){
$ Pid = $ data [$ this-> f_pid];
$ SQL = "select max ({$ this-> f_s}) from {$ this-> table} where {$ this-> f_pid} = $ pid ";
$ Data [$ this-> f_s] = $ this-> db-> getone ($ SQL) + 1; // Obtain the serial number of the node to be inserted.
$ SQL = "select * from {$ this-> table} where {$ this-> f_id} =-1 ";
$ Rs = $ this-> db-> execute ($ SQL );
$ SQL = $ this-> db-> getinsertsql ($ rs, $ data );
$ This-> db-> execute ($ SQL); // Insert node data
If (! $ This-> db-> affected_rows ()){
Return false;
}
$ This-> buildtree (); // the left and right node values are rebuilt.
$ This-> updatelevel (1); // Generate a node-level value
Return true;
}
/**
* Modify node data
* @ Param int $ id node id
* @ Param array $ data node data
* @ Return bool
*/1 2 3 4
Bytes. /Php Tutorial tree structure operation class code /**************...