Welcome Guest, Not a member yet? Register   Sign In
little Pagination/Uri offset problem
#1

[eluser]AzizLight[/eluser]
Hi everybody,
I'm pretty new to CI, I mainly followed videos from BinaryCake and Nettus/Tuts+.
I just finished the lastest nettuts plus tut on pagination in CI, everything works perfectly except that little uri problem.
Basically what happens is that:
-when I'm on page 1, the url is http://localhost:8888/mamp/CodeIgniter/p...ogs/index/
-on page 2 http://localhost:8888/mamp/CodeIgniter/p...gs/index/1
-page 3 http://localhost:8888/mamp/CodeIgniter/p...gs/index/2, etc
where it should be (I think) http://localhost:8888/mamp/CodeIgniter/p...gs/index/3 on page 3.

Here is the code snippet in question:
Code:
function index()
        {
            $this->load->library('pagination');
            
            $config['base_url'] = base_url().'/index.php/blogs/index/';
            $config['total_rows'] =  $this->db->count_all('blogs');
            $config['per_page'] =  1;
            
            $this->pagination->initialize($config);
            
            $data['pagination_links'] = $this->pagination->create_links();
            
            $this->db->order_by('blog_id', 'DESC');
            $data['blog_query'] = $this->db->get('blogs', $config['per_page'], $this->uri->segment(3));
            
            $this->load->view('blog_index', $data);
        }

I tried to change $config['per_page'] to 2 and I got a similar problem:
Code:
$config['per_page'] =  2;
on page 2 the offset was indeed 2 (http://localhost:8888/mamp/CodeIgniter/p...gs/index/2), however on page 3 the offset became 4 (http://localhost:8888/mamp/CodeIgniter/p...gs/index/4).

Now there is clearly something wrong with my code...
Can somebody explain me what's the problem please?
#2

[eluser]GSV Sleeper Service[/eluser]
There's nothing wrong with your code, the documentation is incorrect. the value in the URI is actually the offset, not the page number as it states.
#3

[eluser]AzizLight[/eluser]
Oh ok thanks.
But in that case how would I be able to display the correct page number in the URI please?
#4

[eluser]GSV Sleeper Service[/eluser]
write your own pagination library! the CI one is quite easy to modify




Theme © iAndrew 2016 - Forum software by © MyBB