CodeIgniter Forums
How to minus number in DB - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to minus number in DB (/showthread.php?tid=67050)



How to minus number in DB - falcon812311 - 01-08-2017

PHP Code:
  function minus_set($id)
  {
    $this->db->trans_start();
    $this->db->set('total_set''total_set - 1');
    $this->db->set('price''price - 300.00');
    $this->db->where('user_id'$user_id);
    $this->db->update('users_detail'$data);
    $this->db->trans_complete();

    if ($this->db->trans_status() === TRUE)
    {
      return true;
    }
    else
    {
      return false;
    }
  
This is my model. I want subtract the total set and price. But, its not working.. how to fix it?
thanks


RE: How to minus number in DB - Paradinight - 01-08-2017

(01-08-2017, 05:11 AM)falcon812311 Wrote:
PHP Code:
  function minus_set($id)
  {
    $this->db->trans_start();
    $this->db->set('total_set''total_set - 1');
    $this->db->set('price''price - 300.00');
    $this->db->where('user_id'$user_id);
    $this->db->update('users_detail'$data);
    $this->db->trans_complete();

    if ($this->db->trans_status() === TRUE)
    {
      return true;
    }
    else
    {
      return false;
    }
  
This is my model. I want subtract the total set and price. But, its not working.. how to fix it?
thanks
PHP Code:
    $this->db->set('total_set''total_set - 1',FALSE);
    $this->db->set('price''price - 300.00',FALSE); 
https://www.codeigniter.com/user_guide/database/query_builder.html#CI_DB_query_builder::set


RE: How to minus number in DB - falcon812311 - 01-11-2017

(01-08-2017, 10:18 PM)Paradinight Wrote:
(01-08-2017, 05:11 AM)falcon812311 Wrote:
PHP Code:
  function minus_set($id)
  {
    $this->db->trans_start();
    $this->db->set('total_set''total_set - 1');
    $this->db->set('price''price - 300.00');
    $this->db->where('user_id'$user_id);
    $this->db->update('users_detail'$data);
    $this->db->trans_complete();

    if ($this->db->trans_status() === TRUE)
    {
      return true;
    }
    else
    {
      return false;
    }
  
This is my model. I want subtract the total set and price. But, its not working.. how to fix it?
thanks
PHP Code:
    $this->db->set('total_set''total_set - 1',FALSE);
    $this->db->set('price''price - 300.00',FALSE); 
https://www.codeigniter.com/user_guide/database/query_builder.html#CI_DB_query_builder::set

Thanks!