Php Codeigniter数据不匹配错误弹出消息
我试图做一个错误弹出消息,但在我从谷歌做了很多研究后,所有的教程对我都不起作用。在这个项目中,我使用“rn”和“rn,姓名,D.O.B,年龄,性别,种族,宗教”进行搜索。现在我想为“rn”设置验证。例如:如果“rn”与数据库中的数据不匹配,则会显示错误消息。(很抱歉我的英语不好,因为英语不是我的母语)Php Codeigniter数据不匹配错误弹出消息,php,codeigniter,Php,Codeigniter,我试图做一个错误弹出消息,但在我从谷歌做了很多研究后,所有的教程对我都不起作用。在这个项目中,我使用“rn”和“rn,姓名,D.O.B,年龄,性别,种族,宗教”进行搜索。现在我想为“rn”设置验证。例如:如果“rn”与数据库中的数据不匹配,则会显示错误消息。(很抱歉我的英语不好,因为英语不是我的母语) 这是控制器: <?php class Patient extends CI_Controller { public function __construct() {
这是控制器:
<?php
class Patient extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->model('Patient_model');
}
public function index()
{
$data['content'] = 'patient/search_form';
$data['title']="SEARCH";
$data['sub']='SEARCH PATIENT';
$this->load->view("design/index",$data);
}
public function execute_search()
{
$search_term = $this->input->post('search');
$data['results'] = $this->Patient_model->get_results($search_term);
$this->load->view('patient/search_results',$data);
}
}
这是search_results.php的视图:
<?php $this->load->view('template/header');?>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">Patient Demographic</div>
<div class="panel-body">
<div class="form-group">
<?php
$no=0;
foreach ($results as $row):
$no++;
?>
<table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;">
<tr align='left' >
<th>RN</th> <th> :</th> <th style="font-weight: normal;"><?php echo numberToAlpha($row['rn']);?></th>
<th>Name</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['nama'];?></th>
<th>Date.of.Birth</th> <th>:</th> <th style="font-weight: normal;"><?php echo dateFormat($row['tarikhlahir']);?></th>
<th></th><th></th><th></th>
</tr>
<tr align='left'>
<th>Age </th><th> :</th> <th style="font-weight: normal;"><?php echo calculateCurrentAge ($row['tarikhlahir']);?></th>
<th>Gender</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['jantina'];?></th>
<th>Race</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['bangsa'];?></th>
<th>Religion</th> <th> :</th> <th style="font-weight: normal;"><?php echo $row['agama'];?></th>
</tr>
<?php endforeach ?>
</table>
</div>
</div>
</div>
<?php $this->load->view('template/footer');?>
患者人口统计
注册护士:
姓名:
出生日期:
年龄:
性别:
种族:
宗教:
请大家帮助我,因为我是codeigniter的新手,我从google先生那里学到了很多东西,我周围的人都帮不了我。多谢各位 基本上,如果未找到任何结果,则您的
get_results()
函数将返回一个空数组,并且foreach循环将“失败”。因此,您必须检查计数($results)>0,这意味着您必须检查是否有任何结果:
<?php $this->load->view('template/header');?>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">Patient Demographic</div>
<div class="panel-body">
<div class="form-group">
<?php
if (count($results) > 0):
$no = 0;
foreach ($results as $row):
$no++;
?>
<table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;">
<tr align='left'>
<th>RN</th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo numberToAlpha($row['rn']);?>
</th>
<th>Name</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['nama'];?>
</th>
<th>Date.of.Birth</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo dateFormat($row['tarikhlahir']);?>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align='left'>
<th>Age </th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo calculateCurrentAge ($row['tarikhlahir']);?>
</th>
<th>Gender</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['jantina'];?>
</th>
<th>Race</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['bangsa'];?>
</th>
<th>Religion</th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo $row['agama'];?>
</th>
</tr>
</table>
<?php
endforeach;
else:
?>
<p>No results found</p>
<?php endif; ?>
</div>
</div>
</div>
<?php $this->load->view('template/footer');?>
患者人口统计
注册护士
:
名称
:
出生日期
:
年龄
:
性别
:
比赛
:
宗教
:
未找到任何结果
注意:我在foreach循环中移动了
括号,或者您没有终止表。我不确定您为什么要为每个患者创建一个新表,但我该判断谁;)。如果您不打算使用计数器($no
),也不需要启动计数器。rn
您的列在表中吗?如果我希望“未找到结果”消息成为弹出消息,我该怎么办?这样您就必须使用AJAX和jquery,而且一切都会变得更复杂(超出您的问题范围)。若你们真的想这样做的话,我建议你们研究一下,若你们不能用标签ajax
和jquery
把它贴在堆栈上。
<?php $this->load->view('template/header');?>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">Patient Demographic</div>
<div class="panel-body">
<div class="form-group">
<?php
$no=0;
foreach ($results as $row):
$no++;
?>
<table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;">
<tr align='left' >
<th>RN</th> <th> :</th> <th style="font-weight: normal;"><?php echo numberToAlpha($row['rn']);?></th>
<th>Name</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['nama'];?></th>
<th>Date.of.Birth</th> <th>:</th> <th style="font-weight: normal;"><?php echo dateFormat($row['tarikhlahir']);?></th>
<th></th><th></th><th></th>
</tr>
<tr align='left'>
<th>Age </th><th> :</th> <th style="font-weight: normal;"><?php echo calculateCurrentAge ($row['tarikhlahir']);?></th>
<th>Gender</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['jantina'];?></th>
<th>Race</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['bangsa'];?></th>
<th>Religion</th> <th> :</th> <th style="font-weight: normal;"><?php echo $row['agama'];?></th>
</tr>
<?php endforeach ?>
</table>
</div>
</div>
</div>
<?php $this->load->view('template/footer');?>
<?php $this->load->view('template/header');?>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">Patient Demographic</div>
<div class="panel-body">
<div class="form-group">
<?php
if (count($results) > 0):
$no = 0;
foreach ($results as $row):
$no++;
?>
<table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;">
<tr align='left'>
<th>RN</th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo numberToAlpha($row['rn']);?>
</th>
<th>Name</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['nama'];?>
</th>
<th>Date.of.Birth</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo dateFormat($row['tarikhlahir']);?>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align='left'>
<th>Age </th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo calculateCurrentAge ($row['tarikhlahir']);?>
</th>
<th>Gender</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['jantina'];?>
</th>
<th>Race</th>
<th>:</th>
<th style="font-weight: normal;">
<?php echo $row['bangsa'];?>
</th>
<th>Religion</th>
<th> :</th>
<th style="font-weight: normal;">
<?php echo $row['agama'];?>
</th>
</tr>
</table>
<?php
endforeach;
else:
?>
<p>No results found</p>
<?php endif; ?>
</div>
</div>
</div>
<?php $this->load->view('template/footer');?>