Welcome Guest, Not a member yet? Register   Sign In
[Pagination] Numbering data in pagination
#1

[eluser]Unknown[/eluser]
does anyone ever made numbering data for pagination ?
for example :
the data shown per page = 5, so the number of data is 1-5 on first page, and then on second page sure the number data must 6-10.

so does anyone ever made ?


regards
#2

[eluser]bretticus[/eluser]
It's pretty easy actually.

The uri segment that determines page number is actually the OFFSET, so just loop through your results with a counter variable and add the OFFSET value to the counter.
#3

[eluser]Unknown[/eluser]
[quote author="bretticus" date="1285753082"]It's pretty easy actually.

The uri segment that determines page number is actually the OFFSET, so just loop through your results with a counter variable and add the OFFSET value to the counter.[/quote]

hi bretticus, tnx for your reply, truly I newbie in programming and codeigniter framework, would you like to give me simple code for implement that?


Regards
#4

[eluser]bretticus[/eluser]
In your controller:

Code:
$this->load->library('pagination');              

$offset = ( $this->uri->segment(3) === FALSE ) ? '0' : $this->uri->segment(3);
$data['offset'] = $offset;

$config['base_url'] = site_url('tags');
$config['total_rows'] = $this->tags->count_all();
$config['per_page'] = '20';

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

$data['tags'] = $this->tags->get_all($config['per_page'], $offset);
$data['page_links'] = $this->pagination->create_links();

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

In your view:

Code:
<ul class="listing">
&lt;?php foreach ($tags as $tag_id => $tag): ++$offset?&gt;
  <li>&lt;?=$offset?&gt;. &lt;?=$tag?&gt;</li>
&lt;?php endforeach; ?&gt;
</ul>




Theme © iAndrew 2016 - Forum software by © MyBB