·建站首页 ·钻石 ·繁體
您的位置: 中国建站之家 -> 网站开发设计 -> PHP教程 -> 写不下了

写不下了

作者:未知  来源:转载  发布时间:2005-7-21 8:50:17  发布人:acx

==================================================
file name:
dboper.inc.php
codes:
==================================================
<?
class dboper {
    var $items;
    var $result=0;
    
    function find($l_value) {
        for($j=1;$j<=$this->items["info_all"];$j++) {
            if($l_value==$this->items["d_id][$j]"])
            { return($j);exit; }
        
        }
            
    }
    
    function del($id) {
        //echo "del"." ".$id."<br>";
        include("conn_db.php");
        $Sql_Query="delete from department where d_id=$id";
        $Query_Db=mysql_query($Sql_Query,$Connect);
        
        //echo $Sql_Query;
        include("conn_close.php");
    }
    
    function update($d_id,$f_node,$l_node,$r_node) {
        include("conn_db.php");
        $Sql_Query="update department set f_node=".$f_node.",l_node=".$l_node.",r_node=".$r_node." where d_id=".$d_id;
        $Query_Db=mysql_query($Sql_Query,$Connect);
        
        //echo $Sql_Query;
        include("conn_close.php");
    }
        
    function d_tree($id,$base_id){//
        //echo "do<br>";
        $m=$this->find($base_id);//m is the position of $base_id in arrays
        $i=$this->find($id);
        
        if(($this->items["l_node][$i]"]!=0))
        {    
            //echo "向左下一级";
            //echo "<br>";
            $i=$this->find($this->items["l_node][$i]"]);
            $this->d_tree($this->items["d_id][$i]"],$base_id);
            //exit;
        }
        if(($this->items["r_node][$i]"]!=0)&&($this->items["l_node][$i]"]==0))
        {    
            //echo "向右下一级";
            //echo "<br>";
            $i=$this->find($this->items["r_node][$i]"]);
            $this->d_tree($this->items["d_id][$i]"],$base_id);
            //exit;
        }        
        
        if(($this->items["r_node][$i]"]==0)&&($this->items["l_node][$i]"]==0))
        {
            if($this->result==1){//very important method to exit my function
                return true;
            }
            $this->del($this->items["d_id][$i]"]);
            $j=$i;//save this node information
            $i=$this->find($this->items["f_node][$i]"]);//find it''s parent node
            //begin-----------------------------------------------------
            //if this node is the node you want to delete,delete it and exit function
            if(($this->items["r_node][$i]"]==$base_id)||($this->items["l_node][$i]"]==$base_id))
            {
                $this->result=1;
                return true;
            }
            //end--------------------------------------------------------
            else {
            //begin------------------------------------------------------
            //if this node is the child node of you wanted to deleted node
            //up to parent node and continue find
                if($this->items["r_node][$i]"]==$this->items["d_id][$j]"])
                {
                    //echo "左上一级";
                    //echo "<br>";
                    $this->items["r_node][$i]"]=0;
                    $this->d_tree($this->items["d_id][$i]"],$base_id);
                    //exit;
                }
                
                if($this->items["l_node][$i]"]==$this->items["d_id][$j]"])
                {
                    //echo "右上一级";
                    //echo "<br>";
                    $this->items["l_node][$i]"]=0;
                    $this->d_tree($this->items["d_id][$i]"],$base_id);
                    //exit;
                }
            //end----------------------------------------------------------    
            }
            
        }        
    }    

    function d_node_tree($id,$base_id) {
        $m=$this->find($base_id);//m is the position of $base_id in arrays
        $i=$this->find($id);
        
        if(($this->items["l_node][$m]"]!=0))
        {
            $i=$this->find($this->items["l_node][$m]"]);//current node''s left child node
            $j=$this->find($this->items["f_node][$m]"]);//current node''s parent
            $this->d_tree($this->items["d_id][$i]"],$this->items["d_id][$i]"]);//del whole left child tree
            if($this->items["r_node][$m]"]!=0) {
                if($this->items["r_node][$j]"]==$this->items["d_id][$m]"])//if it''s parent''s right child node
                {
                    $i=$this->find($this->items["r_node][$m]"]);
                    $this->items["r_node][$j]"]=$this->items["d_id][$i]"];
                    $this->update($this->items["d_id][$j]"],$this->items["f_node][$j]"],$this->items["l_node][$j]"],$this->items["r_node][$j]"]);
                    //update where id = $this->items["d_id][$j]"]
                    $this->items["f_node][$i]"]=$this->items["d_id][$j]"];
                    $this->update($this->items["d_id][$i]"],$this->items["f_node][$i]"],$this->items["l_node][$i]"],$this->items["r_node][$i]"]);
                    //update where id = $this->items["d_id][$i]"]
                }
                
                if($this->items["l_node][$j]"]==$this->items["d_id][$m]"])//if it''s parent''s right child node
                {
                    $i=$this->find($this->items["r_node][$m]"]);
                    $this->items["l_node][$j]"]=$this->items["d_id][$i]"];
                    $this->update($this->items["d_id][$j]"],$this->items["f_node][$j]"],$this->items["l_node][$j]"],$this->items["r_node][$j]"]);
                    //update where id = $this->items["d_id][$j]"]
                    $this->items["f_node][$i]"]=$this->items["d_id][$j]"];
                    $this->update($this->items["d_id][$i]"],$this->items["f_node][$i]"],$this->items["l_node][$i]"],$this->items["r_node][$i]"]);
                    //update where id = $this->items["d_id][$i]"]
                }
                $this->del($this->items["d_id][$m]"]);
            }
            
            if($this->items["r_node][$m]"]==0) {
                if($this->items["r_node][$j]"]==$this->items["d_id][$m]"])//if it''s parent''s right child node
                {
                    $this->items["r_node][$j]"]=0;
                    $this->update($this->items["d_id][$j]"],$this->items["f_node][$j]"],$this->items["l_node][$j]"],$this->items["r_node][$j]"]);
                    //update where id = $this->items["d_id][$j]"]
                }
                
                if($this->items["l_node][$j]"]==$this->items["d_id][$m]"])//if it''s parent''s right child node
                {
                    $this->items["l_node][$j]"]=0;
                    $this->update($this->items["d_id][$j]"],$this->items["f_node][$j]"],$this->items["l_node][$j]"],$this->items["r_node][$j]"]);
                    //update where id = $this->items["d_id][$j]"]
                }
                $this->del($this->items["d_id][$m]"]);//del node it self
            }
            return true;
        }
        
        if(($this->items["l_node][$m]"]==0))
        {
            if($this->items["r_node][$m]"]!=0) {
                
                $j=$this->find($this->items["f_node][$m]"]);//current node''s parent
                if($this->items["r_node][$j]"]==$this->items["d_id][$m]"])//if it''s parent''s right child node
                {
                    $i=$this->find($this->items["r_node][$m]"]);//current node''s right child node
                    $this->update($this->items["d_id][

[1] [2]  下一页

将本文收藏到QQ书签与更多好友分享