php - how show notification information -
how show notification "npm kosong" if have 3 condition on model. , how make on controller show notification.
case 1: if condition cek_npm empty = notif "npm empty. check again!"
case 2: if condition cek_npm not empty = notif "npm success absent"
case 3: if condition npm_mhs , kode_absensi not empty = notif "npm have been absent" , sorry english bad.
my model
public function cek_npm($arr){ $arr['npm_mhs'] = $this->input->post('npm_mhs'); $datenow=date("y-m-d"); date_default_timezone_set('asia/jakarta'); //$now = date("h:i:s"); $jam_masuk_absensi=""; $query=$this->db->query("select npm_mhs tbl_mahasiswa npm_mhs= '" . $arr['npm_mhs'] . "'"); if($query->num_rows()==0){ $this->session->set_flashdata('info', 'npm tidak ditemukkan '); //return $query->num_rows(); return null; } $query1=$this->db->query("select kode_absensi tbl_absensi npm_mhs='" . $arr['npm_mhs'] . "' , tgl_absensi='$datenow'"); if($query1->num_rows()>0) { return false; } else{ $data=array( 'npm_mhs'=>$arr['npm_mhs'], 'kode_absensi'=>'1', 'jam_masuk_absensi'=>date('h:i:s'), 'tgl_absensi'=>$datenow ); $this->db->insert('tbl_absensi',$data); return true; } }
my controller:
public function insert_absensi() { $arr['npm_mhs'] = trim($this->input->post('npm_mhs')); if($this->absensi_model->cek_npm($arr['npm_mhs']) == true){ $this->session->set_flashdata('info', 'npm ditemukan sukses absen '); } else{ $this->session->set_flashdata('info', 'npm sudah absen'); } if($this->absensi_model->cek_npm($arr['npm_mhs']) == null) $this->session->set_flashdata('error', 'npm kosong'); }
my view:
$(document).ready(function () { $("#form").validate({ submithandler: function (form) { $.post("<?php echo base_url(); ?>absensi_c/insert_absensi", { npm_mhs: $('#npm_mhs').val(), }, function (data) { window.location = "<?php echo base_url(); ?>absensi_c"; //$('#loadpage').html(data); }); } }); }); function batal() { window.location = "<?php echo base_url(); ?>absensi_c"; }
Comments
Post a Comment