ma'am /先生我有一个问题,我想在我的桌子内查看“未找到搜索”,但是当点击搜索按钮时,它将转到空白页面找不到该搜索:
这是我的模特:
function search($keyword)
{
$this->db->like('Firstname',$keyword);
$this->db->or_like('Middlename',$keyword);
$this->db->or_like('Lastname',$keyword);
$this->db->or_like('Idnumber',$keyword);
$query = $this->db->get('studentinformation');
if ( $query->num_rows() > 0 )
return $query->result();
else
return FALSE;
}
这是我的控制者:
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
if ( !empty($data) )
echo 'Search not found';
else
$this->load->view('result_view',$data);
}
这是我的观点:
<div class="z table-responsive">
<table class=" table table-hover">
<thead >
<tr>
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead><?php
if ( !empty($data) )
echo 'Search not found';
else
{
<tbody>
foreach($results as $row)
{ ?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">Option</a>
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
</div>
答案 0 :(得分:1)
尝试在视图文件中更改以下代码:
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<?php
if ( !isset($results) )
{
echo 'Search not found';
} else{ foreach($results as $row){
?>
<tbody>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">Option</a>
</td>
</tr>
</tbody>
<?php
}
}
?>
</tbody>
</table>
</div>
答案 1 :(得分:0)
尝试此编码
控制器
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
if ( empty($data['results']) )
{
$data['message'] = 'Search not found';
}
$this->load->view('result_view',$data);
}
查看编码
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<tbody>
<?php if ( isset($message) ):
echo "<tr>".$message."</tr>";
else: foreach($results as $row):?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">Option</a>
</td>
</tr>
</tbody>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
答案 2 :(得分:0)
试试这段代码
<强>控制器强>
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
if ($data['result'] == FALSE )
{
$data['message'] = 'Search not found';
$this->load->view('result_view',$data);
}else{
$this->load->view('result_view',$data);
}
}
查看强>
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<tbody>
<?php
if(isset($result)){
foreach($results as $row){
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">Option</a>
</td>
</tr>
<?php
} }
if(isset($meassge))
{
echo $message;
}
?>
</tbody>
</table>