Update data Use SET ,calculation CI3

46 views Asked by At

i have a problem i am new to ci 3 can you guys help me. I have an update query but I want my query to be like this in dalah ci

UPDATE saldo SET saldo = saldo+$nominal WHERE id='$id';

following my controller:

public function updatedebet(){
    if(!$this->session->userdata('username')){
        redirect('auth');
    }else{
        $this->form_validation->set_rules('nominal','nominal','required|trim');
        $this->form_validation->set_rules('id','id','required|trim');
        $id=$this->input->post('id');
        $nominal=$this->input->post('nominal');
            
        $data['id'] = $id;
        $data['nominal'] = $nominal;
        $where=array('id' =>$id);
        $this->M_transaksi->update_data2($where,$data,'saldo');
        $this->session->set_flashdata('message', 
                    '<div class="alert alert-info" role="alert">
                        <strong>Debet Berhasil</strong>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>');
        redirect('admin/saldo');
    }
}

following my models:

public function update_data2($where,$data,$table){
    $this->db->where($where);
    $this->db->update($table,$data);

can you guys help me to change the query above into my update php script on CI3?

0

There are 0 answers