Welcome Guest, Not a member yet? Register   Sign In
Pagination produces the wrong page number
#1

[eluser]gevans[/eluser]
I've been trying to sort out this issue I'm having with the pagination class, but it's the first time I've used it and I'm stumped.

Code:
$this->load->library('pagination');
    $config['base_url'] = base_url().'search/agents/'.$this->uri->segment(3).'/'.$this->uri->segment(4);
    $config['total_rows'] = $all_agents;// 4
    $config['per_page'] = $limit;// 3
    $config['uri_segment']  = 5;

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

The html outputted is

Code:
&nbsp;<strong>1</strong>&nbsp;<a href="http://localhost/site/search/agents/france/alsace/3">2</a>&nbsp;<a href="http://localhost/site/search/agents/france/alsace/3">&gt;</a>&nbsp;

As you can see, though the text in the anchor tag is the number two, the actual href uses a 3. Any ideas?

Cheers,
Gareth
#2

[eluser]gevans[/eluser]
Ignore me, I've always passed page numbers in my URI not the offset. I was under the impression that this pagination script was using page numbers not the offset amount (as it wasn't documented otherwise).

All sorted now.
#3

[eluser]Colin Williams[/eluser]
The parameter for pagination (segment 5) is actually the offset, not the page number. So, page two would have an offset of 3, page 3 would have an offset of 6, etc.

EDIT: Sorry, didn't see your clarification before I posted.
#4

[eluser]gevans[/eluser]
Cheers for that.

I think I could've solved it a lot faster if it wasn't for the fact that I only had 2 pages with an offset or 3. To little things that made it very confusing to have page 2 showing as 3 (so I thought) Wink

Thanks again.
#5

[eluser]David Johansson[/eluser]
I don't like the pagination class, so I rewrote all of it in my own adaptation. One of the changes I made was to let the URI pass the page number instead of the offset.
I also created a function that would receive the current page (instead of getting it from the URI) so it would go throught the same validation process.
Also I made it possible to add inactive prev/next-buttons with custom text if you for instance want to have a grayed out image showing when you can't go to next/prev page (same with first/last)-
Finally I also accept 0 as num_link that would show all pages as links.

If someone's interested in the code PM me Smile




Theme © iAndrew 2016 - Forum software by © MyBB