0

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?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Good code indentation and layout would help us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](https://www.php-fig.org/psr/psr-12/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Feb 23 '23 at 18:12
  • I don't understand because I'm a beginner sr – tantina devega Feb 23 '23 at 18:16

0 Answers0