我有以下查詢插入和刪除預先遍歷數據庫中的記錄。我正在使用codeigniter,並不知道如何在其中激發多個查詢。我嘗試了下面的查詢,但沒有在codeigniter中正確觸發並使用phpmyadmin正確啓動。插入和刪除CodeIgniter中的多個查詢
查詢插入記錄到數據庫:
$level = $_GET['level'] + 1;
$rgt = $_GET['rgt'] + 1;
if ($_GET['level'] == 0) {
$sql = "UPDATE xp_subunit SET lft = lft+2, rgt=rgt+2 WHERE rgt > " . $_GET['rgt'] . "; ";
$sql .="INSERT INTO xp_subunit SET level=" . $level . ", lft =" . $_GET['rgt'] . ", rgt = " . $rgt . " , name = '" . $_GET['name'] . "', unit_id='" . $_GET['unit_id'] . "', description='" . $_GET['description'] . "';";
echo $sql;
} else {
$sql = "UPDATE xp_subunit SET rgt = rgt+2 WHERE rgt > " . $_GET['lft'] . "; ";
$sql .="INSERT INTO xp_subunit SET level=" . $level . ", lft =" . $_GET['rgt'] . ", rgt = " . $rgt . " , name = '" . $_GET['name'] . "', unit_id='" . $_GET['unit_id'] . "', description='" . $_GET['description'] . "';";
echo $sql;
}
echo $query = $this->db->insert($this->tablename, $sql);
查詢從數據庫中刪除記錄:
$sql .= "SELECT @myLeft := " . $_GET['lft'] . ", @myRight := " . $_GET['rgt'] . ", @myWidth := " . $_GET['lft'] . " - lft + 1
FROM xp_subunit WHERE id =" . $_GET['id'] . "; ";
$sql .= "DELETE FROM xp_subunit WHERE lft BETWEEN @myLeft AND @myRight; ";
$sql .= "UPDATE xp_subunit SET rgt = rgt - @myWidth WHERE rgt > @myRight; ";
$sql .= "UPDATE xp_subunit SET lft = lft - @myWidth WHERE lft > @myRight; ";
echo $query = $this->db->mysqli_multi_query($sql);
哪些錯誤與上述疑問?
您還沒有發佈以下你。「哪些錯誤與下面的代碼」 ...... – 2012-07-30 04:46:56
對不起...我編輯它 – Sky 2012-07-30 04:48:33