我不想制作病人登记队列的数量,我今天的数据登记不可用时遇到麻烦。
这是我的代码:
控制器:
function index()
{
$this->load->helper('url');
$data['tbl_pendaftaran'] = $this->m_pendaftaran->getData()->result();
$data['pasien']=$this->m_pendaftaran->getPasien();
$data['kpendaftaran']=$this->m_pendaftaran->get_no_pendaftaran();
//status
$data['status'] = $this->m_pendaftaran->status()->result();
$this->template->load('template','pendaftaran/v_pendaftaran',$data);
}
模特:
function status()
{
$this->db->select('*');
$this->db->from('tbl_pendaftaran');
$this->db->join('tbl_pasien', 'tbl_pendaftaran.id_pasien = tbl_pasien.id');
$this->db->where('status','menunggu');
$this->db->limit(1);
return $this->db->get();
}
查看:
<?php
foreach ($status as $key ) {
}
$cur = date("Y-m-d H:i:s",time());
if ($key->tgl_berobat<$cur) {
echo "No Patient for Today";
} else {
echo $key->no_antrian;
}
?>
当今天的数据不可用时,这是错误的结果:
Severity: Notice
Message: Undefined variable: key
Filename: views/v_pendaftaran.php
Line Number: 22
答案 0 :(得分:1)
看起来你在这里打字错误,或者你错误地关闭了foreach循环:
state
尝试这个:
<?php
foreach ($status as $key ) {
}
$cur = date("Y-m-d H:i:s",time());
if ($key->tgl_berobat<$cur) {
echo "No Patient for Today";
} else {
echo $key->no_antrian;
}
?>
要回复您的评论,请尝试以下方式:
<?php
foreach ($status as $key ) {
$cur = date("Y-m-d H:i:s",time());
if ($key->tgl_berobat < $cur) {
echo "No Patient for Today";
} else {
echo $key->no_antrian;
}
}
?>
答案 1 :(得分:0)
我认为麻烦在你的视野中。 只需将代码更改为
即可<?php
foreach ($status as $key ) {
$cur = date("Y-m-d H:i:s",time());
if ($key->tgl_berobat<$cur) {
echo "No Patient for Today";
} else {
echo $key->no_antrian;
}
}
?>
答案 2 :(得分:0)
在你的控制器中不调用结果函数,导致可能没有对象导致它。
function index()
{
.
.
.
//status
$data['status'] = $this->m_pendaftaran->status();
$this->template->load('template','pendaftaran/v_pendaftaran',$data);
}
首先检查对象是否存在:
<?php
if($status->num_rows()>0)
{
foreach ($status->result() as $key ) {
$cur = date("Y-m-d H:i:s",time());
if ($key->tgl_berobat<$cur) {
echo "No Patient for Today";
} else {
echo $key->no_antrian;
}
}
}
?>