Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. //model
  2. public function importmhs($data) {
  3. $this->db->insert_batch('mahasiswa', $data);
  4. }
  5.  
  6. public function validasinim() {
  7. $this->db->select('nim_mhs');
  8. $this->db->where('nim_mhs');
  9. $query = $this->db->get('mahasiswa');
  10. $num = $query->num_rows();
  11. return $num;
  12. }
  13.  
  14. //controller
  15. $data_upload = $this->upload->data();
  16. $excelreader = new PHPExcel_Reader_Excel2007();
  17. $loadexcel = $excelreader->load('upload/'.$data_upload['file_name']);
  18. $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
  19.  
  20. $data = array();
  21.  
  22. $numrow = 1;
  23. foreach($sheet as $row){
  24. if($numrow > 1){
  25. array_push($data, array(
  26. 'nim_mhs' => $row['A'],
  27. 'nama_mhs' => $row['B'],
  28. 'nohp_mhs' => $row['C'],
  29. 'email_mhs' => $row['D'],
  30. 'set_lulus' => $row['E'],
  31. 'flag_bagidosbing' => $row['F'],
  32. ));
  33. }
  34. $numrow++;
  35. }
  36.  
  37. if ($row['A'] == "" OR $row['B'] == "" OR $row['C'] == "" OR $row['D'] == "") {
  38. $this->session->set_flashdata('error','Data masih ada yang kosong, silahkan cek kembali file excelnya ..');
  39. redirect('koordinator/mahasiswa');
  40. } else {
  41. $ceknim = $this->m_mahasiswa->validasinim($row['A']);
  42. if ($ceknim > 0) {
  43. $this->session->set_flashdata('error','Data ada yang sama, silahkan cek kembali file excelnya ..');
  44. redirect('koordinator/mahasiswa');
  45. } else {
  46. $this->m_mahasiswa->importmhs($data);
  47. unlink(realpath('upload/'.$data_upload['file_name']));
  48. $this->session->set_flashdata('notif','Import File Berhasil ..');
  49. redirect('koordinator/mahasiswa');
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement