2013-02-18 67 views
0

顯示數據庫搜索結果,但分頁鏈接在點擊頁面鏈接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> 

請指導我嘗試了這麼多自己,但沒有得到正確的結果?

+1

get_results()是什麼? – tomexsans 2013-02-18 07:54:59

+0

這是一個模型函數,它爲交易表 – Sushil 2013-02-18 13:20:35

+0

http://phpmaster.com/pagination-with-codeigniter/提供與search_term匹配的結果。 。這裏是一個例子,我真的建議你粘貼你的'get_results()'模型。 。 – tomexsans 2013-02-18 23:05:03

回答

0

最好使用帶有笨應用程序搜索,我發現真正有用的是下面的教程NETTUTS您可以使用多個字段進行搜索記錄和分頁很容易有看它

Search Result tuts

0

這裏一個例子,如何我已實施

在控制器

function index() 
{ 
    $this->load->library('pagination'); 

$config = array(); 
$config["base_url"] = base_url() . "city/index"; 
$config["total_rows"] = $this->city_model->record_count(); 
$config["per_page"] = 20; 
$config["uri_segment"] = 4; 

$this->pagination->initialize($config); 

$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; 
$data["city"] = $this->city_model->get_cities($config["per_page"], $page); 
$data["links"] = $this->pagination->create_links(); 
} 

在模型

function record_count() 
{ 
    return $this->db->count_all("city"); 
} 

function get_cities($limit,$start) 
{  

    $this->db->limit($limit,$start); 
    $this->db->select('*'); 
    $this->db->from('city'); 
    $this->db->order_by('city_name'); 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0) { 
     foreach ($query->result() as $row) { 
     $data[] = $row; 
    } 

return $data; 
} 

return false; 

} 
+0

好的感謝devendra爲您的答案和時間,但我有不同的功能 – Sushil 2013-02-19 10:14:05