0

Hi, I was wondering if it was possible to update the value of a mySQL cell by a method similar to using += in php code. For example, I'd like to do:

$sql = "UPDATE inventory WHERE userID = '$_SESSION[userID]' SET money+='$ssmoney'";

I know I can instead run another query to get the db values, then add the db values to new values, and then run an update query, but I was hoping there was a simpler, more-efficient way. Thanks.

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Kadjii
0

btw I see I have the SET and WHERE reversed in the code above.

0

do you mean like..

UPDATE table_name SET table_name.value = LAST_INSERT_ID(value + 1)

example:
if value is 1
it will update it to be 2

not sure if that is what you are looking for

0

I dont think so.. I dont want it associated with an auto increment column. I just want to treat any int-based cell in a database essentially as a variable and be able to do operations such as x++ or x+=y.

0

It will be look like

$sql = "UPDATE inventory WHERE userID = '$_SESSION[userID]' SET money = money+ $ssmoney ";

Edited by mwasif: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.