显示来自数据库的搜索结果,但是结果分页在codeigniter中不起作用? 大家好,我正在使用codeigniter我在我的视图页面中有一个文本字段,当用户在该字段中输入与我的数据库表相关的任何名称'deals'时,显示与输入字段匹配的交易,但是在该分页链接上不起作用。我点击第二页链接它只是闪烁,因为我使用ajax,我也在输入的期限应用会话,但不能得到现在做什么?
这是我的控制器
class Pagesearch extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('searchmodel');
$this->load->helper('url');
// Load Pagination
$this->load->library('pagination');
$this->load->library('session');
}
public function index($offset = 0)
{
$pagination_per_page = 3;
$config['base_url'] = base_url().'pagesearch/index/';
$config['per_page'] = $pagination_per_page;
$search_term = $this->searchmodel->searchterm_handler($this->input->post('tsd'));
$config['total_rows'] = count($this->searchmodel->get_results($search_term));
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$data['deals_data'] = $this->searchmodel->get_results($search_term, $pagination_per_page, (($offset != 0)?( $pagination_per_page * ($offset - 1)): 0));
$this->load->view('deals/jsonsearch',$data);
}
here it is my model
<?php
class Searchmodel extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_results($search_term, $limit, $offset)
{
$this->db->select('*');
//$this->db->from('deals');
$this->db->like('name',$search_term);
$query = $this->db->get('deals',$limit,$offset);
return $query->result_array();
}
public function searchterm_handler($search_term)
{
if($search_term)
{
$this->session->set_userdata('tsd', $search_term);
return $search_term;
}
elseif($this->session->userdata('tsd'))
{
$search_term = $this->session->userdata('tsd');
return $search_term;
}
else
{
$search_term ="";
return $search_term;
}
}
}
and this is view to display
<div id="dealsData">
<?php foreach ($deals_data as $data): ?>
//some code here to diplay
<?php endforeach ?>
<div id="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
所以请任何能够通过使用ajax在codeigniter中使用分页搜索结果搜索结果的人请给出一些时间&amp;我的解决方案?