0
votes

i am want to update my database where in i have to use the current value (of the column to be updated) do some subtraction to it and then update with the subtracted value
my table is
quantityinhand

qid INT (PK)
itemId INT (FK)
quantity INT

my query is
"Update quantityinhand SET quantity=quantity-".$qty." where itemId=".$itemId;
here $qty is the quantity to be subtracted and $itemId is the item Id whoose quantity is to be updated
How to write this query in ZEND framework

please help Thanks

1
There are many ways..you mean Zend_Db_Table or Zend_Db_Select or Zend_Db_Adapter? - bitWorking
my class extends the Zend_Db_Table_Abstract - Navin Kanjwani

1 Answers

1
votes

Replace Bugs with your Table class. (Not tested)

$table = new Bugs();
$qty = 10;
$itemId = 1;

$data = array(
    'quantity' => new Zend_Db_Expr('quantity - '.$qty),        
);

$where = $table->getAdapter()->quoteInto('itemId = ?', $itemId);

$table->update($data, $where);