another pagination problem

#1
[eluser]gwood[/eluser]
I am implementing pagination a record set off a custom db query. For this I am passing a value by using URI segment to the query based on which the records are returned. Now, the first page of the result appears correctly. But then when I click pg2, it shows error as it now longer takes the correct URI segment as argument. That segment now actually turns to the page number and it takes it as an argument and so no record are returned. Well, if I messing it up for you, here's it in simple term...

Code:
http://localhost/cit/index.php/books/tags/fiction/

I use this URI (books controller, tags function, and fiction is the param) to find books in db table that are tagged as fiction. Now if I use
Code:
http://localhost/cit/index.php/books/tags/
as the base URI for pagination, the pagination link turns like
Code:
http://localhost/cit/index.php/books/tags/10
. Note that 10 here is not the param for tag but the offset for page 2 of the paged record set. And hence it returns empty row. I tried using a session variable but then it looks like the new URI segment overwrites the session variable too!

How do I work around this??? Also, is there any way I can make the pagination link appear as say,
Code:
http://localhost/cit/index.php/books/tags/fiction/10
that is baseURI then, param and then pagination offset.
Thank you!

#2
[eluser]theprodigy[/eluser]
Quote:I use this URI (books controller, tags function, and fiction is the param)

It may not be the best way to handle it, but for your current setup, you could always try:
Code:
class Books extends Controller{
//..other code..
function tags($type = null, $page = 0)
{
    if(is_numeric($type))
    {
        $page = $type;
        $type = null;
    }
    //..other code..
}

and then run the rest of your code as normal. This is assuming you don't have a book type that is numeric.

#3
[eluser]pickupman[/eluser]
You can double check the pagination docs, but you need to change your uri segment. It defaults to 3, and you need the fourth.
Code:
$type = $this->uri->segment(3,'fiction');

$config['uri_segment'] = 4; //Important Revision
$config['total_rows'] = $query->num_rows(); //Total number of results
$config['per_page'] = 10;
$config['base_url'] = site_url('books/tags/'.$type.'/');
$this->pagination->initialize($config);

There are several posts about this problem, you may want to try and search the forums.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.