猿问

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

我目前在将值从数据库中扣除到我的字段时遇到问题


这是我的代码


在我的模型中,我有一个名为 deduct


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'),

            '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'),

        );


    }




ibeautiful
浏览 142回答 1
1回答

汪汪一只猫

$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);    }
随时随地看视频慕课网APP
我要回答