如何显示通知" NPM Kosong"如果我在模型上有3个条件。以及如何在控制器上显示通知。
案例1:如果条件cek_npm为空= notif" NPM为空。再次检查!"
情况2:如果条件cek_npm不为空= notif" NPM成功缺席"
情况3:如果条件npm_mhs和kode_absensi不为空= notif" NPM已经缺席"谢谢你,我很抱歉我的英语很糟糕。
我的模特
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 from tbl_mahasiswa where 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 from tbl_absensi where npm_mhs='" . $arr['npm_mhs'] . "' and 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;
}
}
我的控制员:
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');
}
我的观点:
$(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";
}