• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with update data (reduce value)

#1
[eluser]Carmichael[/eluser]
Code:
function reduce_credits($id, $credits)
   {
        $this->db->where('user_id', $id);
        $this->db->update($this->user_table, 'user_credits = user_credits - '.$credits.'');
   }

When I run that function it updates the user_credits column to 0 insted of reduce the current value. Why?


#2
[eluser]Carmichael[/eluser]
I solved it

Code:
$this->db->where('user_id',$id);
        $this->db->set('user_credits','user_credits - ' . $credits, FALSE);
        $result = $this->db->update($this->user_table);

#3
[eluser]Samus[/eluser]
Because the 2nd parameter is expected to be an array.

But explain what you're trying to do abit.

I'm a little confused here:

Code:
user_credits = user_credits - '.$credits.''

Something tells me you're trying to subtract the value of column 'user_credits' by $credits?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.