I’m using codeigniter pagination here is my code
$config['base_url'] = $this->config->base_url().'users/allusers/';
$config['uri_segment'] = 3;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['total_rows'] = $this->usersmodel->getUsersCount();
$config['per_page'] = 20;
$this->pagination->initialize($config);
$data['paging']=$this->pagination->create_links();
$data['query']=$this->usersmodel->getAllusers($config['per_page'],$this->uri->segment(3));
Now i need to add record numbers to the grid here is my grid code.
$i=1;
foreach ($query->result() as $row){
echo $i;
echo $row->username;
echo $row->name;
echo $row->city;
echo $row->address;
$i++;
}
?>
Here the $i is always printing the numbers 1-20 even when i’m in second page. actually i need to print 20-40
I need to know how can i do that?
You must set $i to the value of the current page minus one, multiplied by the number of rows in a page:
Replace:
with
If cur_page is inaccessible, try to extend the pagination class with something like this:
Create a file called MY_Pagination.php and put it in application/libraries/
Add this code to your extend pagination class;
Don’t forget to make sure the class extension prefix is set correctly to MY_ in the config.php (about line 109)
Then you can access it like so:
I used and slightly modified some content from this question:
How to echo page number with codeigniter pagination library?