Tree structure is a lot of program members will use, the above on the tree-type structure of the Operation class, a good solution to this problem oh.
/php Tutorial Tree-type structure Operation class code
/***************************************************************
* Tree structure operation class (ideal if it can be written as a stored procedure)
*
* ***************************************************************/
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 function
* @param string $table table name
* @param object $dbhanle ADODB Database tutorial action handle
*/
Function TreeNode ($table, $dbhandle) {
$this->db = $dbhandle;
$this->table = $table;
$this->db->debug = true;
}
/**
* Add child nodes
* @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;//Gets the ordinal 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); Inserting node data
if (! $this->db->affected_rows ()) {
return false;
}
$this->buildtree (a); Rebuilding node left and right values
$this->updatelevel (1); Generate node-level values
return true;
}
/**
* Modify the data of the node
* @param int $id Node ID number
* @param array $data node data
* @return BOOL
*/1 2 3 4
http://www.bkjia.com/PHPjc/444898.html www.bkjia.com true http://www.bkjia.com/PHPjc/444898.html techarticle tree structure is a lot of program members will use, the above on the tree-type structure of the Operation class, a good solution to this problem oh. /php Tutorial Tree-type structure operation class Code/************** ...