Cakephp Save Update Data From Old Data Value + New Value
I don't know the keyword to search with my problem. How to save update data of a field that already exist a value and I want to update it with additional value. Here is an example
Solution 1:
updateAll will work
$this->User->updateAll(
array('credit' => "credit + $newCredit"),
array('id' => $userId)
);
Solution 2:
Try this one:
$userData = array(
'id' => $userId,
'credit' => 'credit +'.$newCredit// old credit value + new credit value
);
$this->User->save($userData);
Or this:
$newCredit = 566;
$this->User->read(null, $userId);
$this->User->set('credit',$this->User->field('credit') + $newCredit);
$this->User->save();
Post a Comment for "Cakephp Save Update Data From Old Data Value + New Value"