0

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'
UPDATE absensi SET keterangan = Array, ket = Array WHERE id_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...

1 Answers1

1

change your model to this

public function ubahAbsen($data)
{
  $dataUpdate = array(
    'keterangan' => $data['keterangan'],
    'ket' => $data['ket']
  );
  $this->db->where('id_siswa', $data['id_siswa']);
  $this->db->update('absensi', $dataUpdate);
}

because variable $data contains single data siswa

Danz
  • 252
  • 1
  • 8