Update multiple data in Codeigniter

Asked by At

I have a table with the name 'session_kriteria' (in english: session criteria) where the table has 3 fields namely id_sesi, kode_kriteria (in english: criterion code), and bobot (in english: weight). at the beginning of the data is already filled with 4, namely IPK, KTI, PKD, BI with default 'bobot' = 0.

Then I have form to update the weight. And the form is like this: enter image description here

For example we fill in as shown below: enter image description here

But I found an error like this: enter image description here

And my code is like this (update method):

public function update($id) 
        $row = $this->Sesi_kriteria_model->get_by_id($id);

        if ($row) {
            $data = array(
                'button' => 'Update',
                'action' => site_url('sesi_kriteria/update_action'),
  'id_sesi' => set_value('id_sesi', $row->id_sesi),
        'ambil_data_sesi' => $this->Sesi_kriteria_model->sesi(),
  'kode_kriteria' => set_value('kode_kriteria', $row->kode_kriteria),
        'ambil_semua' => $this->Sesi_kriteria_model->ambil_semua_bid($id),
        'ambil_data_kriteria' => $this->Sesi_kriteria_model->kriteria(),
  'bobot' => set_value('bobot', $row->bobot),
            $this->template->set('title', 'Ubah Bobot Kriteria');
            $this->template->load('index', 'contents' , 'sesi_kriteria/sesi_kriteria_update', $data);
        } else {
            $this->session->set_flashdata('message', 'Record Not Found');

And the action method for update is like this:

    public function update_action() 
        if ($this->form_validation->run() == FALSE) {
            $this->update($this->input->post('id_sesi', TRUE));
        } else {
            $sesi_array = $this->input->post('id_sesi', TRUE);
            $kriteria_array = $this->input->post('kode_kriteria[]', TRUE);
            $bobot_array = $this->input->post('bobot[]', TRUE);
            for($i=0; $i<sizeof($sesi_array); $i++){
                        $dt = array(            
                            'id_sesi' => $this->input->post($sesi_array[$i], TRUE),
                            'kode_kriteria' => $this->input->post($kriteria_array[$i], TRUE),
                            'bobot' => $this->input->post($bobot_array[$i], TRUE),
                $this->db->replace('bobot', $bobot_array);
                $this->db->where('id_sesi', $sesi_array);
            $this->db->update('sesi_kriteria', $data, 'id_sesi');
            $this->session->set_flashdata('message', 'Create Record Success');

1 Answers

Shahriar63 On

What is your tabel column name ? REPLACE INTO botbot (0,1,2,3) VALUES ('10','20','30','40') Does the botbot table column table name is 0,1,2,3