在codeigniter中写入查询

时间:2014-10-28 11:21:14

标签: sql codeigniter

SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1
FROM nested_category
WHERE name = 'MP3 PLAYERS';

DELETE FROM nested_category WHERE lft BETWEEN @myLeft AND @myRight;

UPDATE nested_category SET rgt = rgt - @myWidth WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft - @myWidth WHERE lft > @myRight;

UNLOCK TABLES;

我的codeigniter代码:

function deletecategory($id)
{   
      $Q = $this->db->query('SELECT  * FROM categorymaster where cat = "'.$id.'"');

        if ($Q->num_rows() > 0)
                {
                        foreach ($Q->result_array() as $row)
                        {
                            $rightextent = $row['rightextent'];
                            $leftextent = $row['leftextent'];
                            $width=$rightextent-$leftextent+1;
                        }
                } else {
                    $rightextent=0;
                }

            $this->db->where('id',$id);
            $this->db->delete('categorymaster');

            $width=$rightextent-$leftextent+1;

            $Q2 = $this->db->query('update categorymaster set rightextent=rightextent-"'.$width.'" where rightextent > "'.$rightextent.'"');

            $Q1 = $this->db->query('update categorymaster set leftextent=leftextent-"'.$width.'" where leftextent > "'.$rightextent.'"');
}

当我删除当时的根节点时,也删除他们的子节点并更新他们的左右范围

0 个答案:

没有答案