显示数据库搜索结果,但单击页面链接 2 时分页链接不起作用?这里是我的控制器函数 pagesearch,它从我的视图文件中获取 search_term,它是要搜索的单词的输入文本字段
<?php
class Pagesearch extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('searchmodel');
$this->load->helper('url');
// Load Pagination
$this->load->library('pagination');
}
public function execute_search($offset=0)
{
$search_term = $this->input->post('tsd');
echo $search_term;
$pagination_per_page = 3;
// Config setup
$config['base_url'] = site_url('pagesearch/execute_search');
$config['per_page'] = $pagination_per_page;
$config['total_rows'] = count($this->searchmodel->get_results($search_term));
$config['uri_segment'] = 2;
$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 for like query where $search
class Searchmodel extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_results($search_term, $limit, $offset=0)
{
$this->db->select('*');
$this->db->like('name',$search_term);
$query = $this->db->get('deals',$limit,$offset);
return $query->result_array();
}
}
here it is view code look like this
<div id="dealsData">
<?php foreach ($deals_data as $data): ?>
//some code
<?php endforeach ?>
<div id="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
请指导我自己尝试这么多但没有得到正确的结果?