xuzuning (唠叨) 大哥,你准备干嘛?

解决方案 »

  1.   

    <?phpclass Tree_control 
    {
        function Tree_control( $sql )
        {
            $this->tbl_struct = $sql;
            $this->tbl_name = $_GLOBAL['_CONFIG']['tbl_name'];
            $this->basenum= pow(2,16);
        }    function Add( $deep )
        {
            $sql = "SELECT max(ordernum) AS basenum FROM {$this->tbl_name}";
            $this->query( $sql );        $basenum=$this->eof?$this->basenum:$this->fields->basenum;        $sql = "INSERT INTO {$this->tbl_name}
                    SET deep= $deep, ordernum= $basenum";
            $this->query($sql);
            return $this->insertID();        
        }    function AddChild( $parentID )
        {
            $sql = "SELECT root_id, deep, ordernum FROM {$this->tbl_name}
                    WHERE id>= $parentID LIMIT 2";        $this->query( $sql );
            $root_id = empty( $deep ) ? $parentID : $this->fields->root_id;
            $ordernum= $this->fields->ordernum;
            $deep     = $this->fields->deep + 1;
            $this->next();
            $ordernum= ( ordernum + $this->fields->ordernum ) / 2;        $sql = "INSERT INTO {$this->tbl_name}
                    SET root_id=$root_id, deep=$deep,ordernum=$ordernum)";
            $this->query( $sql );
            return $this->insertID();
        }    functin AddFirst( $offsetID )
        {
            $sql = "SELECT root_id, deep, ordernum FROM {$this->tbl_name}
                    WHERE id <= $offsetID LIMIT 2";
            $this->query( $sql );        $root_id = $this->fields->root_id;
            $ordernum= $this->fields->ordernum;
            $deep     = $this->fields->deep;
            $this->next();
            $ordernum2 =  $this->eof ? 0 :$this->fields->ordernum;
            $ordernum= ( ordernum + ordernum2 ) / 2;        $sql = "INSERT INTO {$this->tbl_name}
                    SET root_id=$root_id, deep=$deep,ordernum=$ordernum)";
            $this->query( $sql );
            return $this->insertID();
        }
        function AddLast( offsetID )
        {
            $sql = "SELECT root_id, deep, ordernum FROM {$this->tbl_name}
                    WHERE id >= $offsetID LIMIT 2";
            $this->query( $sql );        $root_id = $this->fields->root_id;
            $ordernum= $this->fields->ordernum;
            $deep     = $this->fields->deep;
            $this->next();
            $ordernum2 =  $this->eof ? $ordernum * 2 :$this->fields->ordernum;
            $ordernum= ( ordernum + ordernum2 ) / 2;        $sql = "INSERT INTO {$this->tbl_name}
                    SET root_id=$root_id, deep=$deep,ordernum=$ordernum)";
            $this->query( $sql );
            return $this->insertID();
        }}
    ?>
    不知道对不对,我还没测试
    move我还没想出来,好像只更改root_id不行吧?