lookee Posted October 26, 2008 Share Posted October 26, 2008 I am attempting to add a quantity to an exisiting field in a Mysql table. For instance. Current_Inventory 8 I would like to increase the amount of 8 by 4 to equal 12. Code $query = "UPDATE nixon SET quantity=$books WHERE group_id=9"; mysql_query($query); Right now, the above code simply replaces 8 with 4. How would I write the code to add the amounts together? Would I have to do something like - fetch the current inventory and assign a $current_string to that amount - assign a $new_string to the addition amount - add the two amounts together by assigning the sum of both to an $updated_string? Or is there a simple Mysql command that will do this? Thanks! Link to comment https://forums.phpfreaks.com/topic/130199-how-to-add-data-to-existing-data-to-get-a-new-total/ Share on other sites More sharing options...
xtopolis Posted October 27, 2008 Share Posted October 27, 2008 UPDATE nixon SET quantity = (quantity + $books) WHERE group_id = 9 you can use the existing column to modify that rows data Link to comment https://forums.phpfreaks.com/topic/130199-how-to-add-data-to-existing-data-to-get-a-new-total/#findComment-675340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.