php - cakephp save update data from old data value + new value -
I do not know the keyword to search with my problem How to save the update data in a field that already A value exists and I want to update it with additional value.
Here is an example cakephp:
$ userData = array ('id' = & gt; $ userId, 'credit' => $ newCredit // Only updates new credits); $ This- & gt; User- & gt; Save ($ userdata);
If I use the usual query MySQL, then it will be like this:
mysql_query ("UPDATE` user` set` credit` = `credit `+ '$ NewCredit' where` id` = '$ userId' ");
You can see only one time to update the normal code with the existing code credit
I know that I SELECT
I can do this data using and can operate in php
, then return the UPDATE
data, but it will be 2 times (select, then update).
So what can cakephp do it at once? And how: D?
will work
$ this-> gt; ; User- & gt; Updates (Array ('credit' = & gt; "Credit + $ new credit)", array ('id' => user $ Id););
Comments
Post a Comment