PHP头条
热点:

php 树型结构操作类代码(1/4)


树型结构是很多程序会员会用到的,上面这款关于树型结构操作类,很好的解决了这个问题哦。

/php教程 树型结构操作类代码
/***************************************************************
* 树型结构操作类(如果可以写成存储过程最理想)
*
*  ***************************************************************/

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;
        /**
         * 构造函数
         * @param string $table 表名
         * @param object $dbhanle adodb数据库教程操作句柄
         */
        function treenode($table, $dbhandle) {
                $this->db = $dbhandle;
                $this->table = $table;
                //$this->db->debug = true;
        }
        /**
         * 增加子节点
         * @param array $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;//得到待插入节点的序号
                $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); //插入节点数据
                if(!$this->db->affected_rows()){
                        return false;
                }
               
                $this->buildtree(1,1);        //重建节点左右值
                $this->updatelevel(1);        //生成节点级数值
                return true;
        }
        /**
         * 修改节点的数据
         * @param int $id 节点id号
         * @param array $data 节点数据
         * @return bool
         */ 1 2 3 4

www.phpzy.comtrue/php/11883.htmlTechArticlephp 树型结构操作类代码(1/4) 树型结构是很多程序会员会用到的,上面这款关于树型结构操作类,很好的解决了这个问题哦。 /php教程 树型结构操作类代码 /************************************...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐