2013-01-06 47 views
1

這裏是我的控制器:笨分頁第3頁的鏈接成爲殘疾

class Comment extends CI_Controller { 

function article() { 
    $this->load->library('pagination'); 
    $this->load->model('comment_m'); 
      $id=$this->uri->segment(3); 
    $config['base_url'] = 'http://localhost/ci/CodeIgniter_2.1.3/index.php/comment/article/'.$id; 
    $config['total_rows'] = $this->db->get('comment_article')->num_rows(); 
      $config['per_page'] = 5; 
    $config['num_links'] = 5; 
    $config['full_tag_open'] = '<div id="pagination">'; 
    $config['full_tag_close'] = '</div>'; 
    $this->pagination->initialize($config); 
      echo $this->uri->segment(4); 
      $data['c_review'] = $this->comment_m->getarticle($id, $config['per_page'], $this->uri->segment(4)); 

      $this->load->view('comment_v', $data); 
} 
} 

這裏是我的模型:

class Comment_m extends CI_Model{ 

function getarticle($id,$limit,$start) { 
    $this->db->select('name, content'); 
    $this->db->from('comment_article'); 
      $this->db->where('article_id', $id); 
      $this->db->limit($limit, $start); 
    $q = $this->db->get(); 

    if($q->num_rows() > 0) { 
     foreach ($q->result() as $c_review) { 
      $data[] = $c_review; 
     } 
     return $data; 
    }  

} 
} 

分頁工作正常,如果我有小於或等於10篇( 2頁),但如果我有第三個分頁鏈接,那麼第三個鏈接變得不可循環,而不是一個錨標籤。 我在我的其他頁面中使用了相同的分頁,它工作正常,但是這是導致此問題的原因。

以下是分頁頁面圖片的鏈接。這裏突出顯示的頁面是3,而活動頁面仍然是1,所以第三頁面是不可靠的。

This is the link to the image

這是我的其他實現這我不能夠實現這個分頁,但是這就是我想要的:這裏的當前頁是第1次和總的13個項目都是有每頁5個項目。

This is link to the desired implementation

+0

試** $配置[ 'first_url'] =「localhost/ci/CodeIgniter_2.1.3/index.php/comment/article /".$ id; ** – sbaaaang

+0

也嘗試啓用輸出分析器和/或ci日誌來檢查發生了什麼 – sbaaaang

+0

@Badaboooooom from where我們可以啓用輸出分析器和ci日誌嗎? – user1953363

回答

0

還有的觀點,你有問題,TOTAL_ROWS它可以讓你選擇的行數從數據庫中未總數更好地使用count_all或count_all_result如果你使用任何在where子句只是改變它

from 
$config['total_rows'] = $this->db->get('comment_article')->num_rows(); 

to 
$config['total_rows'] = $this->db->get('comment_article')->count_all(); 

多了一個變化,這將幫助您在其他的服務器

from 
$config['base_url'] = 'http://localhost/ci/CodeIgniter_2.1.3/index.php/comment/article/'.$id; 

to 
$config['base_url'] = base_url('comment/article/'.$id); // it will automatically add default base_url 

莫您部署項目ST importand你必須添加$配置[「uri_segment」]你必須告訴哪個段是默認頁面數爲3

$config['uri_segment'] = 3; 

對分頁文檔的外觀上CI網站

+0

我認爲這是事實。它採取了第三個網址段,但我想要第四個。它正在工作。 – user1953363