【问题标题】:Update multiple data in Codeigniter在 Codeigniter 中更新多个数据
【发布时间】:2019-04-11 04:29:12
【问题描述】:

我有一个名为“session_kriteria”(英文:会话标准)的表格,该表格有 3 个字段,即 id_sesi、kode_kriteria(英文:标准代码)和 bobot(英文:重量)。 数据开头已经填充了4,即IPK、KTI、PKD、BI,默认'bobot'=0。

然后我有表格来更新重量。表格是这样的: enter image description here

例如我们填写如下图: enter image description here

但我发现了这样的错误: enter image description here

而我的代码是这样的(更新方式):

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');
            redirect(site_url('sesi_kriteria'));
        }
    }

更新的动作方法是这样的:

    public function update_action() 
    {
        $this->_rules();
        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);
            
            $data=array();
            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');
            redirect(site_url('sesi_kriteria'));
        }

【问题讨论】:

    标签: php arrays codeigniter sql-update


    【解决方案1】:

    您的表列名称是什么? 替换成botbot (0,1,2,3) 值 ('10','20','30','40') botbot表列表名是否为0,1,2,3

    【讨论】:

    • 没有。没有名称为 botbot 的表。 'botbot' 是 'criteria_session' 表的字段名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2016-09-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    相关资源
    最近更新 更多