0

I don't know how can I update data in column instead of replacing it. For example now I made simple purchase system and when someone make payment, his old data in the column if it was 5 and the purchase value if its 10, its not going 15 its automatically replacing the old data and adding the new one = 10. Here is the code:

public function updateCoinsRewards($data){
    $IGN = $this->session->userdata['Player_Logged']['id'];

    $update = $this->db->where('id', $IGN);
    $update = $this->db->update($this->CoinsRewards,$data);
    return $update?true:false;
}

I tried to make data update instead data replace but didn't make it. Expectation is instead of replacing old data as I said, to add the new one.

Dharman
  • 30,962
  • 25
  • 85
  • 135
traplord
  • 1
  • 1
  • [Increment field of mysql database using codeigniter's active record syntax](https://stackoverflow.com/q/6373564/2943403) , [Codeigniter increase value in database from array with only one component escaped](https://stackoverflow.com/q/59367206/2943403) , [Codeigniter, increase database value by value contained in variable](https://stackoverflow.com/q/6889828/2943403) , [How to update the column with increment value](https://stackoverflow.com/q/35415341/2943403) , [CodeIgniter model - create method for updating any column in any table](https://stackoverflow.com/q/19983001/2943403) – mickmackusa Jan 31 '23 at 20:47
  • [CI update_batch; Concatenate and increment variable and string as array value](https://stackoverflow.com/q/31816009/2943403) , [Increment article views on the fly within one row in CodeIgniter](https://stackoverflow.com/q/13939333/2943403) , [add a value to existing value using mysql query](https://stackoverflow.com/q/48528295/2943403) , [how to subtract a value from a field in PHP codeigniter?](https://stackoverflow.com/q/32352313/2943403) , [Updating a field subtract from a variable](https://stackoverflow.com/q/10191214/2943403) – mickmackusa Jan 31 '23 at 20:53
  • You need to say $this->db->update($this->CoinsRewards, array('coins' => $previousRow->coins + 5); or simpler like "update TableX set Coins = Coins + 5 where ID = X" – Marius Jan 31 '23 at 21:59
  • ^ that's the TL;DR of all of my found duplicates (except you don't need to use a raw query, CI's active record syntax can handle the task just fine). – mickmackusa Jan 31 '23 at 22:01
  • [How do I do this query with ActiveRecord Class from Code Igniter?](https://stackoverflow.com/q/3349791/2943403) , [Update database current field](https://stackoverflow.com/q/34063081/2943403) , [How to update inventory when a new purchase is made ? MySQL, PHP, Codeigniter](https://stackoverflow.com/q/44925315/2943403) , [CodeIgniter UPDATE query not working with column value addition](https://stackoverflow.com/q/42881152/2943403) – mickmackusa Jan 31 '23 at 22:11
  • [How can I select and update a column value in single query with codeIgniter](https://stackoverflow.com/q/42060931/2943403) , [Decrease column value via update query with join clause using CI's active record](https://stackoverflow.com/q/17950763/2943403) , [how to increase database column value by one?](https://stackoverflow.com/q/12920962/2943403) , [CodeIgniter UPDATE query not working with column value addition](https://stackoverflow.com/q/42881152/2943403) – mickmackusa Feb 01 '23 at 19:42
  • [unable to increment or decrements database column value in codeigniter](https://stackoverflow.com/q/53154961/2943403) , [Sum of multiple row and insert into another column using Codeigniter not working](https://stackoverflow.com/q/40807353/2943403) , [How to update value of particular column in database in codeigniter](https://stackoverflow.com/q/51941770/2943403) , [Codeigniter Query Update set from another field](https://stackoverflow.com/q/60809566/2943403) – mickmackusa Feb 01 '23 at 20:50
  • [Trying to update a row in the db with codeigniter just doing +1 but doesn't seem to be working](https://stackoverflow.com/q/61822847/2943403) , [Incrementing value in a database codeigniter](https://stackoverflow.com/q/12756364/2943403) , [Increment database value with php](https://stackoverflow.com/q/21274144/2943403) , [update in code igniter not updating record](https://stackoverflow.com/q/53881539/2943403) – mickmackusa Feb 02 '23 at 01:57
  • [code igniter with mysql: add value via set?](https://stackoverflow.com/q/32273833/2943403) , [Codeigniter active record query](https://stackoverflow.com/q/6995543/2943403) , [Proper way to escape query in Codeigniter](https://stackoverflow.com/q/29084297/2943403) – mickmackusa Feb 02 '23 at 07:51

0 Answers0