Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //model
- public function importmhs($data) {
- $this->db->insert_batch('mahasiswa', $data);
- }
- public function validasinim() {
- $this->db->select('nim_mhs');
- $this->db->where('nim_mhs');
- $query = $this->db->get('mahasiswa');
- $num = $query->num_rows();
- return $num;
- }
- //controller
- $data_upload = $this->upload->data();
- $excelreader = new PHPExcel_Reader_Excel2007();
- $loadexcel = $excelreader->load('upload/'.$data_upload['file_name']);
- $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
- $data = array();
- $numrow = 1;
- foreach($sheet as $row){
- if($numrow > 1){
- array_push($data, array(
- 'nim_mhs' => $row['A'],
- 'nama_mhs' => $row['B'],
- 'nohp_mhs' => $row['C'],
- 'email_mhs' => $row['D'],
- 'set_lulus' => $row['E'],
- 'flag_bagidosbing' => $row['F'],
- ));
- }
- $numrow++;
- }
- if ($row['A'] == "" OR $row['B'] == "" OR $row['C'] == "" OR $row['D'] == "") {
- $this->session->set_flashdata('error','Data masih ada yang kosong, silahkan cek kembali file excelnya ..');
- redirect('koordinator/mahasiswa');
- } else {
- $ceknim = $this->m_mahasiswa->validasinim($row['A']);
- if ($ceknim > 0) {
- $this->session->set_flashdata('error','Data ada yang sama, silahkan cek kembali file excelnya ..');
- redirect('koordinator/mahasiswa');
- } else {
- $this->m_mahasiswa->importmhs($data);
- unlink(realpath('upload/'.$data_upload['file_name']));
- $this->session->set_flashdata('notif','Import File Berhasil ..');
- redirect('koordinator/mahasiswa');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement