Welcome Guest, Not a member yet? Register   Sign In
Pagination - links go up by 10 instead of 1?
#1

[eluser]sheldonnbbaker[/eluser]
Code:
$config['uri_segment'] = 4;
$config['total_rows'] = 17;
$config['per_page'] = 10;

My paging links go up by 10 - like /archive/10, /archive/20 (instead of the /archive/1, archive/2 that I want).

Is this by design or am I doing something wrong?

Thanks Smile
#2

[eluser]Thorpe Obazee[/eluser]
It is 'by design' I believe. You can search the wiki or the forums for extensions. I believe some people built something to get the pagination 'right'.
#3

[eluser]TheFuzzy0ne[/eluser]
It's to give you more control.
#4

[eluser]xwero[/eluser]
Yes it's by design. The paging segment contains the offset. This is to make it easier for the developer to query the database segment that is wanted.
#5

[eluser]wiredesignz[/eluser]
CodeIgniter libraries are notoriously stupid, but you might like to try the Pager Widget
http://ellislab.com/forums/viewthread/111908/
#6

[eluser]TheFuzzy0ne[/eluser]
I wouldn't go as far as to say they are stupid, they are just generic, and not tailored to everyone's needs. Each page represents a result, and just like when you read a book, you only go to the next page, where there's a new result, you don't skip 10 pages with every turn of the page.
#7

[eluser]xwero[/eluser]
The offset is not something that should be displayed, it's a really lazy developers solution. An extreme example is to just use database/table/offset/limit in the url and let the users figure out what they need.

Or to stay in the book analogy, the pages aren't numbered by the paragraphs they contain.
#8

[eluser]TheFuzzy0ne[/eluser]
As I said, the pagination class is just a generic class. If you want to use a page number and not the offset, you can add the calculations to your logic.

Code:
$config['total_rows'] = ceil($result->num_rows() / $actual_results_per_page);
$config['per_page'] = 1;

I haven't tried this, but I can't see why it shouldn't work. Obviously, your model would just have to do some extra calculations.

Code:
$offset = ($current_page_number * $actual_results_per_page) - $actual_results_per_page;

Again, it's untested, but should work.

So, you do have the ability to do it whichever way you want to do it.
#9

[eluser]wiredesignz[/eluser]
[quote author="TheFuzzy0ne" date="1239977600"]... they are just generic, and not tailored to everyone's needs.[/quote]

Which means none of us really like the way CI pagination works.
#10

[eluser]xwero[/eluser]
Setting the per_page to 1 works, but have you ever wondered why the pagination plugin needs to know how many records are going to be displayed? The number of records is only important for the model.

The hack would be
Code:
$limit = 10;

$config['total_rows'] = ceil($result->num_rows()/$limit);
$config['per_page'] = 1;
// ...
$data['pagination'] = $this->pagination->create_links($config);
$data['content'] = $this->some_model->get_content($limit,$page_segment*$limit);




Theme © iAndrew 2016 - Forum software by © MyBB