顯示數據庫搜索結果,但分頁鏈接在點擊頁面鏈接2時不起作用? 這裏我控制器功能pagesearch其獲取SEARCH_TERM從那裏輸入文本字段的話我認爲文件中搜索顯示數據庫搜索結果,但點擊頁面鏈接2時分頁鏈接不工作?
<?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>
請指導我嘗試了這麼多自己,但沒有得到正確的結果?
get_results()是什麼? – tomexsans 2013-02-18 07:54:59
這是一個模型函數,它爲交易表 – Sushil 2013-02-18 13:20:35
http://phpmaster.com/pagination-with-codeigniter/提供與search_term匹配的結果。 。這裏是一個例子,我真的建議你粘貼你的'get_results()'模型。 。 – tomexsans 2013-02-18 23:05:03