我正在使用zend,我有以下代码,如
class Admin_Model_DbTable_Inv extends Zend_Db_Table_Abstract
{
protected $_name = 'test';
public function updateproductstock($qty,$pid)
{
$data = array(
'stock' => 'stock - 2'
);
$this->_db->update($this->_name, $data, product = '.$pid.');
}
}
在这里,我想从库存中减去我的数量。例如2将是数量。 qty
将是动态数据。如何在此处使用zend update。请帮助。
更新了我的帖子
答案 0 :(得分:2)
class Admin_Model_DbTable_Inventory extends Zend_Db_Table_Abstract
{
protected $_name = 'test';
public function updateproductstock($qty,$pid)
{
$data = array(
'stock' => new Zend_Db_Expr('stock - '.$qty);
);
$this->_db->update($this->_name, $data, product = '.$pid.');
}
}
答案 1 :(得分:0)
class Admin_Model_DbTable_Inv extends Zend_Db_Table_Abstract
{
protected $_name = 'test';
public function updateproductstock($qty)
{
$r = $this->fetchRow($this->select()->where('product = ?', 1));
$r->stock -= $qty;
$r->save();
$data = array(
'stock' => 'stock - '.(string) $qty;
);
$this->_db->update($this->_name, $data, "product = '1'");
}
}
ps:所有变量都应该是前缀$