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.

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

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

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.

It will be look like

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

Great. Thanks so much!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.