Select, Insert, Delete Multiple Data Codeigniter
1. untuk multiple delete
function hapusallterkirim(){
$nis=$this->input->post('check');
$jumlah=count($nis);
$hasil=array();
for ($a=0;$a<$jumlah;$a++){
$query="delete from sentitems where ID='$nis[$a]'";
$result=$this->db->query($query);
$hasil[$a]=$result;
}
return $hasil;
}
2. untuk multiple insert
function simpanujian(){
$data=array();
foreach($_POST['nis'] AS $key => $val){
$data[]=array(
"IDUJIAN" => $_POST['nis'][$key].$_POST['mapel2'].$_POST['jenis'].$_POST['semester'],
"IDSISWA" => $_POST['nis'][$key],
"IDKELAS" => $_POST['idkelasmm'],
"IDJENIS" => $_POST['jenis'],
"IDSEMESTER" => $_POST['semester'],
"IDMAPEL" => $_POST['mapel2'],
"NILAIP" => $_POST['nilaip'][$key],
'NILAIK' => $_POST['nilaik'][$key],
"NILAIS" => $_POST['nilais'][$key],
"TANGGAL" => $_POST['tanggal']
);
}
$this->db->insert_batch('tbl_ujian',$data);
}
3.untuk multiple selection query
function ambilwalitampung(){
$nis=$this->input->post('nis');
$jumlah=count($nis);
$hasil=array();
for ($a=0;$a<$jumlah;$a++){
$query="select * from tbl_wali_siswa where NISWALI='$nis[$a]'";
$result=$this->db->query($query)->row();
$hasil[$a]=$result;
}
return $hasil;
}
function hapusallterkirim(){
$nis=$this->input->post('check');
$jumlah=count($nis);
$hasil=array();
for ($a=0;$a<$jumlah;$a++){
$query="delete from sentitems where ID='$nis[$a]'";
$result=$this->db->query($query);
$hasil[$a]=$result;
}
return $hasil;
}
2. untuk multiple insert
function simpanujian(){
$data=array();
foreach($_POST['nis'] AS $key => $val){
$data[]=array(
"IDUJIAN" => $_POST['nis'][$key].$_POST['mapel2'].$_POST['jenis'].$_POST['semester'],
"IDSISWA" => $_POST['nis'][$key],
"IDKELAS" => $_POST['idkelasmm'],
"IDJENIS" => $_POST['jenis'],
"IDSEMESTER" => $_POST['semester'],
"IDMAPEL" => $_POST['mapel2'],
"NILAIP" => $_POST['nilaip'][$key],
'NILAIK' => $_POST['nilaik'][$key],
"NILAIS" => $_POST['nilais'][$key],
"TANGGAL" => $_POST['tanggal']
);
}
$this->db->insert_batch('tbl_ujian',$data);
}
3.untuk multiple selection query
function ambilwalitampung(){
$nis=$this->input->post('nis');
$jumlah=count($nis);
$hasil=array();
for ($a=0;$a<$jumlah;$a++){
$query="select * from tbl_wali_siswa where NISWALI='$nis[$a]'";
$result=$this->db->query($query)->row();
$hasil[$a]=$result;
}
return $hasil;
}