Reputation: 11
I'm following this tutorial for using the pagination library within codeigniter. I've implemented the tutorial correctly and am even displaying my results in descending order with mysql.
However, codeigniter's pagination library continues to generate links that are in ascending order
public function example1() {
$config = array();
$config["base_url"] = base_url() . "welcome/example1";
$config["total_rows"] = $this->Countries->record_count();
$config["per_page"] = 5;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Countries->
fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("example1", $data);
}
With this code, the links go up by 5 starting at link 1 and stops at total_rows. I want it to count down from total_rows by 5 instead and stop at 0, how do I do this?
Another example:
1 2 3 4 5 > Last »
How would I reverse this list to look something like this:
5 4 3 2 1 > Last »
Upvotes: 1
Views: 471
Reputation: 11
I landed on this answer by accident, searching for help to reverse the order of pagination RESULTS in CI (not the pagination LINKS). I found the answer in the documentation but thought it might be useful to someone who also landed here accidentally for the same reason.
To reverse the order of PAGINATED RESULTS you can use the orderBy() clause in CI4 (not sure about CI3).
// ----- paginate
$elements = $model->orderBy('id','DESC')->paginate(20); // << 'DESC' is reverse
Here is the entire code (in a CI Controller class)
$model = new \Ignition\Blog\Forms\Index;
$elements = $model->orderBy('id','DESC')->paginate(20);
Then you would call your CI view() with the $elements.
Docs here: https://codeigniter.com/user_guide/libraries/pagination.html
Upvotes: 0
Reputation: 11
You can do it using css
$config['attributes'] = array('class' => 'pagination-link');
Make linkes inline-block a.pagination-link{display: inline-block;}
Then give it direction : rtl
Upvotes: 1