我使用CodeIgniter分頁類來爲每頁數據分頁10行。我正在使用foreach循環。Increasinging運算符在Foreach循環中進行分頁
我的問題是,循環遞增運算符在第二個,第三個&下一個分頁頁面中重置爲1。
第1頁的屏幕截圖[僞數據僅]:
第2頁的屏幕截圖[僞數據僅]:
第3頁的屏幕截圖[僞數據僅]:
我控制器:
<?php
class Mypagination extends CI_Controller{
function index(){
$this->load->database();
$this->load->library('pagination');
$config['base_url'] = '/codeigniter/index.php/mypagination/index/';
$config['total_rows'] = $this->db->get('tracking')->num_rows();
$config['per_page'] = 10;
$config['next_link'] = 'Next';
$this->pagination->initialize($config);
$data['query'] = $this->db->get('tracking', $config['per_page'], $this->uri->segment(3));
$this->load->view('mypagination_view', $data);
}
}
我的觀點:
<?php
$i = 1;
foreach($query->result() as $row){
echo $i++ . ') ';
echo $row->name . ' - ' . $row->email;
echo '<br>';
}
echo $this->pagination->create_links();
?>
我想要增加運營商在未來的分頁的頁面繼續像11,12,13 ...在第二頁。 21,22,23在第三頁...
如何解決這個問題?
對不起,如果這是太基本的問題。我只是CodeIgniter和PHP的新手。
謝謝。但$ i = 1 + $ this-> pagination-> cur_page * $ this-> pagination-> per_page;沒有爲我工作@АндрейПочекуев。 –
已編輯。現在應該工作。問題是,在使用'create_links()'方法之前,分頁沒有得到當前頁面。 – Eternal1
現在我明白了這一點http://i.imgur.com/NIv9huF.jpg –