Welcome Guest, Not a member yet? Register   Sign In
Pagination with page number as uri rather than offset
#2

[eluser]jblack199[/eluser]
Well, while I havent used the pagination class with CI I have used pagination in other things as well as written custom pagination classes for use without any MVC or template engines.

I've taken a quick look at the pagination class, and first thing you'd have to change it:

var $per_page = 10; // Max number of items you want shown per page

would need to be in your controller before the query itself..

2nd thing in your controller you'd need to SELECT COUNT(*) FROM tbl WHERE to get the total count... once you get the count you'd need to get the total pages... CI pagination class does this through use of:

// Calculate the total number of pages
$num_pages = ceil($this->total_rows / $this->per_page);

in the create_links function... you could use the prebuilt functionality to do it just fine really...

I imagine you'd then change this:

Code:
if ($n == '' && $this->first_url != '')
                        {
                            $output .= $this->num_tag_open.'<a >anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
                        }
                        else
                        {
                            $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;

                            $output .= $this->num_tag_open.'<a >anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
                        }

to this
Code:
if ($n == '' && $this->first_url != '')
                        {
                            $output .= $this->num_tag_open.'<a >anchor_class.'href="'.$loop.'">'.$loop.'</a>'.$this->num_tag_close;
                        }
                        else
                        {
                            $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;

                            $output .= $this->num_tag_open.'<a >anchor_class.'href="'.$this->base_url.$loop.'">'.$loop.'</a>'.$this->num_tag_close;
                        }

doing that, would at least get the URL's to look correctly... the math involved in finding the offset would be up to you to figure out...


Messages In This Thread
Pagination with page number as uri rather than offset - by El Forum - 08-10-2011, 10:50 AM
Pagination with page number as uri rather than offset - by El Forum - 08-10-2011, 01:46 PM
Pagination with page number as uri rather than offset - by El Forum - 08-10-2011, 02:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB