Php 搜索的codeigniter分页不工作
在这里,控制器调用搜索函数并执行分页。我正在获取输出,但搜索结果的分页不起作用,因为当我单击分页的前向链接时,它起作用,但当我单击分页的后向链接时,它将显示数据库的信息,而不是搜索的信息。我刚刚接触codeigniter,不知道该怎么办 Controller main.phpPhp 搜索的codeigniter分页不工作,php,codeigniter,pagination,Php,Codeigniter,Pagination,在这里,控制器调用搜索函数并执行分页。我正在获取输出,但搜索结果的分页不起作用,因为当我单击分页的前向链接时,它起作用,但当我单击分页的后向链接时,它将显示数据库的信息,而不是搜索的信息。我刚刚接触codeigniter,不知道该怎么办 Controller main.php public function search() { if($this->session->userdata('is_logged_in')) { $this->
public function search()
{
if($this->session->userdata('is_logged_in'))
{ $this->load->model('model_users');
$config = array();
$config["base_url"] = base_url() . "main/search";
$config["total_rows"] = $this->model_users->get_count();
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$config['next_link'] = '>';
$config['prev_link'] = '<';
$this->pagination->initialize($config);
// $data['offset_no'] = $this->uri->segment(3);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$match = $this->input->post('search');
$data["results"] = $this->model_users->
get_search($config["per_page"], $page, $match);
$data["links"] = $this->pagination->create_links();
$this->load->view('search', $data);
}
else
{
redirect('main/restricted');
}
}
modelmodel_users.php
public function get_search($limit, $start, $match)
{
$this->db->limit($limit, $start);
$this->db->select('*');
$this->db->from('users');
$this->db->like('name',$match, 'before');
$this->db->or_like('address',$match, 'before');
$this->db->or_like('email',$match, 'before');
$query = $this->db->get();
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$data[]= $row;
}
return $data;
}
else return False;
}
public function get_count()
{
$match = $this->input->post('search');
$this->db->select('*');
$this->db->from('users');
$this->db->like('name',$match, 'before');
$this->db->or_like('address',$match, 'before');
$this->db->or_like('email',$match, 'before');
$query = $this->db->get();
return count($query->result());
}
视图:search.php
<div class="search">
<?=form_open('main/search');?>
<?php $search = array(
'name'=>'search',
'id' => 'search',
'style' => 'height:25px',
'style' => 'align:center',
'value' => $this->input->post('search')
);
?>
<?=form_input($search);?><input type=submit value='Search' /></p>
<?=form_close();?>
</div>
<?php
if($results) {
echo "<table border='1'>
<tr>
<th> USER_ID </th>
<th> USER_NAME</th>
<th> EMAIL</th>
<th> USER_ADDRESS</th>
<th> CONTACT_NO</th>
<tr> ";
foreach($results as $row){
echo "<tr>";
echo "<td>" .$row->id. "</td>";
echo "<td>" .$row->name. "</td>";
echo "<td>" .$row->email. "</td>";
echo "<td>" .$row->address. "</td>";
echo "<td>" .$row->contact_no. "</td>";
echo"</tr>";
}
echo"</table>";
}
else
{
echo "No results was found in the table for
this keyword " .$this->input->post('search'); }
?>
<p><?php echo $links; ?></p>
试试这个
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td>###</td>
</tr>
</tbody>
你犯了什么错误?请在此处转储错误。嘿,我没有收到任何错误,我收到了搜索结果,但该搜索结果的分页不起作用。。。当我点击next pagelink时,它不会加载数据库的搜索信息,而是数据库的所有信息都会出现在下一个链接中。我认为分页链接有问题。检查元素并检查href第二个链接生成,可能没有调用有效的控制器/方法。