I have a table that stores a value that will be added over time. When I want to add a value that I would like to make in a single query, and not -
- Get oldValue from database
- newValue = oldValue + X
update row using newValue
$ query1 = "SELECT value FROM table WHERE id = thisID"; $ result1 = mysql_query ($ query1); while ($ row = mysql_fetch_array ($ result)) {$ oldValue = $ row ['value']; } $ newValue = $ oldValue + x $ query1 = "UPDATE table SET value = $ newValue WHERE id = thisID";
Can this be done in one request?
source
share