CodeIgniter Forums
Pagination Bug - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Pagination Bug (/thread-45819.html)



Pagination Bug - El Forum - 10-07-2011

[eluser]zenixgrace[/eluser]
I Don't exactly sure is a bug or not

i use CI v2.0.2

i got some issue wen't pass query_string minus value

seem like the digit links is not show in my page

example : i have a 12 rows and my configuration per_page is 4
i pass url like that http://localhost/CI/test/index/-1 or whatever that have a minus value
i got link like that < > (Just Only Prev and Next link show)

i try to fix pagination library code like that

search that code like that
Code:
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
        {
            if ($CI->input->get($this->query_string_segment) != 0)
            {
                $this->cur_page = $CI->input->get($this->query_string_segment);

                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }
        else
        {
            if ($CI->uri->segment($this->uri_segment) != 0)
            {
                $this->cur_page = $CI->uri->segment($this->uri_segment);

                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }


replace with that
Code:
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
        {
            if ($CI->input->get($this->query_string_segment) > 0)
            {
                $this->cur_page = $CI->input->get($this->query_string_segment);

                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }
        else
        {
            if ($CI->uri->segment($this->uri_segment) > 0)
            {
                $this->cur_page = $CI->uri->segment($this->uri_segment);

                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }

i also get an issue wen't i pass query_string value is my last record row

example : i have 12 row in database
my configuration is like that :
$config['base_url'] = site_url('test/index');
$config['total_rows'] = $this->testmodel->count_all();
$config['per_page'] = 4;
$this->pagination->initialize($config);

when i pass a url like that http://localhost/CI/test/index/12
i got link like that First < 2 3
i think it's should like that < 1 2 3 because the default num_link is 2

i try to fix pagination library code like that

search that code like that
Code:
if ($this->cur_page > $this->total_rows)
        {
            $this->cur_page = ($num_pages - 1) * $this->per_page;
        }


replace with that
Code:
if ($this->cur_page >= $this->total_rows)
        {
            $this->cur_page = ($num_pages - 1) * $this->per_page;
        }



i don't exactly sure that the best way or not
may be someone can explain / fixed that with better ways..

Correct Me If I'm Wrong (CMIIW)