2014-02-22 72 views
0

我想每頁使用分頁顯示一個事實,但它在一個頁面中顯示所有事實。如何使用分頁顯示每頁上的一個項目

這裏是控制器正在使用

$config = array(); 
    $config["base_url"] = base_url() . "Admin/news/index"; 
    $config["total_rows"] = $this->news_model->record_count(); 
    $config["per_page"] = 2; 
    $config["uri_segment"] = 1; 

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

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data["results"] = $this->news_model->fetch_countries($config["per_page"], $page); 
    $data["links"] = $this->pagination->create_links(); 

這是模型

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

public function fetch_countries($limit, $start) { 
    $this->db->limit($limit, $start); 
    $query = $this->db->get("knowbank"); 

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

}

最後我看來

   <?php foreach ($news as $news_item): ?> 
     <div class="col1"><?php echo $news_item['title'] ?></div> 
     <img src="<?php echo base_url('image/' .$news_item['picture']);?>" style="max-width:210px; max-height:180px;"><br />&nbsp;&nbsp; 
     <p><?php echo $news_item['body'] ?></p> 
     <p>Category: &nbsp; <?php echo $news_item['category']?><br /><br /> 
     Posted on:&nbsp; <?php echo $news_item['date']?> 
     </p> 
     <a href="news/view/<?php echo $news_item['slug'] ?>" class="btn">View article</a><br /><br /> 
     <?php endforeach ?> 
     <?php echo $links; ?> 
+0

'$ config [「uri_segment」] = 3;'試試這個 –

+0

同樣的區別。它不會改變 –

回答

0

更改以下和嘗試,你的PA ge offset是url的最後一段,所以它的4

$config["per_page"] = 1; 
$config["uri_segment"] = 4; 


$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; 
+0

它沒有改變。可能是什麼問題呢? –

+0

你可以在$ query = $ this-> db-> get(「knowbank」)後面的模型中使用html形式'$ data [「links」]'和echo $ this-> db-> last_query()'。 ;'併發布 – Minhaz

+0

請檢查我的看法..我已經更新了。也許這可能是問題 –

相關問題