为了账号安全,请及时绑定邮箱和手机立即绑定

如何从数据库codeigniter中扣除价值

如何从数据库codeigniter中扣除价值

PHP
ibeautiful 2022-01-14 16:42:52
我目前在将值从数据库中扣除到我的字段时遇到问题这是我的代码在我的模型中,我有一个名为 deductpublic function deduct($id){        $data = array(            'loan' => $this->input->post('loan'),            'id' => $id,            'loan_type' => $this->input->post('loan_type'),            'loan_amount' => $this->input->post('loan_amount'),            'firstname' => $this->input->post('firstname'),            'lastname' => $this->input->post('lastname'),            'middlename' => $this->input->post('middlename'),            'gender' => $this->input->post('gender'),            'civilstatus' => $this->input->post('civilstatus'),            'birthday' => $this->input->post('birthday'),            'age' => $this->input->post('age'),            'dependents' => $this->input->post('dependents'),            'spousefirstname' => $this->input->post('spousefirstname'),            'spouselastname' => $this->input->post('spouselastname'),            'spousemiddlename' => $this->input->post('spousemiddlename'),            'spouseage' => $this->input->post('spouseage'),            'spousebirthday' => $this->input->post('spousebirthday'),            'homeaddress' => $this->input->post('homeaddress'),            'zipcode' => $this->input->post('zipcode'),            'lengthofstay' => $this->input->post('lengthofstay'),            'hometype' => $this->input->post('hometype'),        );    }
查看完整描述

1 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

$this->db->set('loan_amount','loan_amount-balance', false);它不会生效,因为您设置$data了$this->db->update('employee',$data);.


这将解决您的问题:)


public function deduct($id){


        $data = array(

            'loan' => $this->input->post('loan'),

            'id' => $id,

            'loan_type' => $this->input->post('loan_type'),

            'loan_amount' => $this->input->post('loan_amount') - $this->input->post('cash_amount'),

            'firstname' => $this->input->post('firstname'),

            'lastname' => $this->input->post('lastname'),

            'middlename' => $this->input->post('middlename'),

            'gender' => $this->input->post('gender'),

            'civilstatus' => $this->input->post('civilstatus'),

            'birthday' => $this->input->post('birthday'),

            'age' => $this->input->post('age'),

            'dependents' => $this->input->post('dependents'),

            'spousefirstname' => $this->input->post('spousefirstname'),

            'spouselastname' => $this->input->post('spouselastname'),

            'spousemiddlename' => $this->input->post('spousemiddlename'),

            'spouseage' => $this->input->post('spouseage'),

            'spousebirthday' => $this->input->post('spousebirthday'),

            'homeaddress' => $this->input->post('homeaddress'),

            'zipcode' => $this->input->post('zipcode'),

            'lengthofstay' => $this->input->post('lengthofstay'),

            'hometype' => $this->input->post('hometype'),

            'emailaddress' => $this->input->post('emailaddress'),

            'homephonenumber' => $this->input->post('homephonenumber'),

            'businessphonenumber' => $this->input->post('businessphonenumber'),

            'mobilenumber' => $this->input->post('mobilenumber'),

            'nameofbusiness' => $this->input->post('nameofbusiness'),

            'natureofbusiness' => $this->input->post('natureofbusiness'),

            'addressofbusiness' => $this->input->post('addressofbusiness'),

            'yearsofbusiness' => $this->input->post('yearsofbusiness'),

            'nameofcomaker' => $this->input->post('nameofcomaker'),

            'addressofcomaker' => $this->input->post('addressofcomaker'),

            'numberofcomaker' => $this->input->post('numberofcomaker'),

            'balance' => $this->input->post('cash_amount')

        );


        $this->db->where('id', $id);

        $this->db->update('employee',$data);

    }



查看完整回答
反对 回复 2022-01-14
  • 1 回答
  • 0 关注
  • 114 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信