Zend framework Zend只执行两个表更新中的一个
我有一段代码来更新元素的位置Zend framework Zend只执行两个表更新中的一个,zend-framework,zend-db,Zend Framework,Zend Db,我有一段代码来更新元素的位置 public function moveUp($id) { $row = $this->find($id)->current(); $kategoria = $row->kategoria; $position = $row->position; if($position > 1) { $data1 = array(
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?这是假设应用程序的其他部分中的代码不会在位置列中留下空白。好的,我找到了答案。第一次更新后,两行的
位置相同
,因此第二次更新会影响两行而不是一行
通过添加
$where2['id != ?'] = $id;
是否尝试手动执行第一个查询?可能是您的
where
子句无效