Anda mencoba memasukkan larik di dalam for insertStudentData[key]
.
Coba Ini:
$insertStudentData[$key] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo'],
'is_active' => $studentDatas['is_active']['0']['photo'],
);
$this->db->insert('users_student', $insertStudentData[$key]);
jika Anda mencoba menyisipkan beberapa baris, Anda dapat menggunakan masukkan_batch
Saya telah mencoba kode Anda di pihak saya dan itu menjadi sangat benar. itu menambahkan beberapa baris ke tabel. Inilah yang telah saya lakukan.
function create($studentData){
$insertStudentData = ''; //Create a Variable
foreach ($studentData => $studentDatas) {
$insertStudentData[] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo']['0']['photo'],
'is_active' => $studentDatas['is_active']
);
}
$this->db->insert_batch('users_student', $insertStudentData[$key]);
if($this->db->affected_rows() != 1){
return false;
} else {
return true;
}
}