dsgo31121 2017-07-25 01:51
浏览 83
已采纳

使用set减去更新查询中的列值

I am working on a database column value (int) to subtract and update using set.

I am using $this->db->set() to subtract and update column value in codeigniter.

The problem is when I run the query the column value get change to null.

  1. $this->db->set('app_balance', 'app_balance'. - $app_work_charge.'');
  2. $this->db->where('id', $app_id);
  3. $this->db->update('app');

In my log file it will not showing any error.

More Explanation: if column value is 200 and if I will want to subtract 10 from it then after query execution it will change to null.

  • 写回答

1条回答 默认 最新

  • drcrc28428 2017-07-25 01:55
    关注

    Write false at the end of the first line and put - after field name.

    1. $this->db->set('app_balance', 'app_balance-'. $app_work_charge.'',false);
    2. $this->db->where('id', $app_id);
    3. $this->db->update('app');
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部