Php tree structure operation code (1/4) _ PHP Tutorial

Source: Internet
Author: User
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 /**************...

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.