I'm new in Codeigniter.. I try to do the batch update on my code but it return an error "Array to string conversion and error like this :
Unknown column 'Array' in 'field list'
UPDATEabsensi
SETketerangan
= Array,ket
= Array WHEREid_siswa
= '1'
Below is the code on Controller :
$input = $this->input->post();
$id_mapel = $input['id_mapel'];
$id_kelas = $input['id_kelas'];
$index = 0;
foreach ($input['id_siswa'] as $key => $val) {
$data = [
'id_siswa' => $input['id_siswa'][$key],
'id_mapel' => $input['id_mapel'],
'id_kelas' => $input['id_kelas'],
'time_in' => time(),
'tanggal' => date("d"),
'bulan' => date("m"),
'tahun' => date("Y"),
'keterangan' => $input['keterangan'][$key],
'ket' => $input['ket'][$key]
];
$this->guru_m->ubahAbsen($data);
}
redirect('gr/absensi');
}
On model :
public function ubahAbsen($data)
{
foreach($this->input->post('id_siswa') as $key => $value)
{
$data = array(
'keterangan' => $this->input->post('keterangan'),
'ket' => $this->input->post('ket')
);
$this->db->where('id_siswa', $value);
$this->db->update('absensi', $data);
}
}
Can you tell me the correct code? I'm really dizzy to fix this error...