2
我有這小小的一段代碼更新元素Zend公司只執行兩個表的更新
public function moveUp($id) {
$row = $this->find($id)->current();
$kategoria = $row->kategoria;
$position = $row->position;
if($position > 1) {
$data1 = array(
'position' => new Zend_Db_Expr('position - 1')
);
$where1['id = ?'] = $id;
$this->getDefaultAdapter()->update($this->_name, $data1, $where1);
$data2 = array(
'position' => new Zend_Db_Expr('position + 1')
);
$where2['position = ?'] = $position - 1;
$where2['kategoria = ?'] = $kategoria;
$this->getDefaultAdapter()->update($this->_name, $data2, $where2);
}
}
問題的立場是,只有第二次更新被執行,第一個什麼都不做。如果我註釋掉第二個更新,那麼第一個更新工作正常。這是爲什麼?
我也應該檢查下一個較小/較大的位置,而不是隻有+/- 1嗎?這是假設應用程序其他部分的代碼不會在位置列中留下空白。
固定它試圖通過手工執行你的第一個查詢?這可能是你的'where'子句是無效的 –