Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Arrray to String conversion error when perform batch update

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$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…

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading