2011-07-25 87 views
0

我經過一些幫助CodeIgniter分頁(修復一個錯誤)..我可以看到在視圖中的記錄數和分頁鏈接,但點擊下一個鏈接時,它不顯示下一個/上一個10記錄。有人可以幫助我嗎?CodeIgniter分頁

我有我的控制器

function customerlist_pagination() 
{ 
    $search = $this->input->post('search'); 
    $data['title'] = "Customer Clist"; 
    $data['heading'] = "List of customers"; 
    $data['result'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "limit_rows"); 
    $data['num_recs'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "num"); 
    $config['base_url'] = base_url().'index.php/customer/customerlist_pagination/'; 
    $config['total_rows'] = $data['num_recs']; 
    $config['per_page'] = 10; 
    $config['uri_segment'] = 3; 
    $config['next_link'] = 'Next >'; 
    $config['prev_link'] = '< Previous '; 
    $this->pagination->initialize($config); 
    $this->load->view('customer_view_table',$data); 
} 

在模型下面的代碼,我有以下代碼:

function getAllSeizures_pagination($search_para, $archive_search = FALSE, $result_type) 
{ 
    $search_para = $search_para."%"; 
    $selected_fields = "customer.firstName 
    customer.lastName, customer.address, 
    customer.city, customer.postcode"; 
    $from = "customer";  
    $where = "customer.deleted=0 "; 
    if ($archive_search == TRUE) { 
     $where .= "AND customer.archived= 1 "; 
    }else{ 
     $where .= "AND customer.archived= 0 "; 
    } 
    $where .= "AND (customer.firstName LIKE '$search_para' OR customer.postcode LIKE '$search_para' OR customer.city LIKE '$search_para')"; 
    $query = $this->db->select($selected_fields, false) 
        ->from($from) 
        ->where($where)  
        ->order_by('customer.idcustomer', 'desc'); 

    if($result_type == "limit_rows") 
    { 
     $query = $this->db->limit(10, 0) 
         ->get(); 
     $query = $query->result(); 
    } 

    if($result_type == "num") { 
     $query = $this->db->get(); 
    $query = $query->num_rows(); 
    } 

    return $query; 
} 

非常感謝

問候 普拉斯

+0

你噠你的記錄是多少算tabase表? – toopay

+0

它返回25,這是所有記錄...和極限是10 – pks

+0

那麼,那沒什麼不對。如果你想在你的分頁導航中顯示一個序列號,至少你必須有60個或更多的記錄,然後在你的分頁配置中添加'$ config ['num_links'] = 2;',一切都會像你想的那樣。 – toopay

回答

0

的分頁類將uri_seg中的偏移量傳遞給您指定。既然你把它設置爲3,您應該捕獲這些信息在你的控制器方法的第一個變量,就像這樣:

function customerlist_pagination($offset) 
{ 
} 

然後,當你打電話給你$this->customers_model->getAllcustomers_pagination(),你必須通過它的$offset,這樣以後在你的代碼,你限制你的結果:

$query = $this->db->limit(10, 0)->get(); 

你應該使用這個$offset來限制你的結果:

$query = $this->db->limit(10, $offset)->get();