CodeIgniter Forums
Pagination in descending order - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Pagination in descending order (/showthread.php?tid=76857)



Pagination in descending order - mohs3n - 06-27-2020

Hi

In my controller I have this :

Code:
$article = new Article();
$data = [
            'articles' => $article->paginate(5),
            'pager' => $article->pager
        ];

echo view('panel/template', $data);

Which loads the records from the article table and uses the pagination module to limit the number of records per page in the view file.
The pagination module loads the records in ascending order by default but I need to have them in Descending order which means I need the new articles to be on the first page.

Any idea how to do that?


RE: Pagination in descending order - wdeda - 06-27-2020

(06-27-2020, 08:15 AM)mohs3n Wrote: Hi

In my controller I have this :

Code:
$article = new Article();
$data = [
            'articles' => $article->paginate(5),
            'pager' => $article->pager
        ];

echo view('panel/template', $data);

Which loads the records from the article table and uses the pagination module to limit the number of records per page in the view file.
The pagination module loads the records in ascending order by default but I need to have them in Descending order which means I need the new articles to be on the first page.

Any idea how to do that?

Have you tried this?

PHP Code:
$article = new Article();
$data = [
            'articles' => $article->orderBy('id''DESC')
            ->paginate(5),
            'pager' => $article->pager
        
];

echo 
view('panel/template'$data); 



RE: Pagination in descending order - mohs3n - 06-27-2020

(06-27-2020, 02:31 PM)wdeda Wrote:
(06-27-2020, 08:15 AM)mohs3n Wrote: Hi

In my controller I have this :

Code:
$article = new Article();
$data = [
            'articles' => $article->paginate(5),
            'pager' => $article->pager
        ];

echo view('panel/template', $data);

Which loads the records from the article table and uses the pagination module to limit the number of records per page in the view file.
The pagination module loads the records in ascending order by default but I need to have them in Descending order which means I need the new articles to be on the first page.

Any idea how to do that?

Have you tried this?

PHP Code:
$article = new Article();
$data = [
            'articles' => $article->orderBy('id''DESC')
            ->paginate(5),
            'pager' => $article->pager
        
];

echo 
view('panel/template'$data); 

Nice one wdeda
That worked.


RE: Pagination in descending order - wan12 - 11-09-2021

(06-27-2020, 02:31 PM)wdeda Wrote:
(06-27-2020, 08:15 AM)mohs3n Wrote: Hi

In my controller I have this :

Code:
$article = new Article();
$data = [
            'articles' => $article->paginate(5),
            'pager' => $article->pager
        ];

echo view('panel/template', $data);

Which loads the records from the article table and uses the pagination module to limit the number of records per page in the view file.
The pagination module loads the records in ascending order by default but I need to have them in Descending order which means I need the new articles to be on the first page.

Any idea how to do that?

Have you tried this?

PHP Code:
$article = new Article();
$data = [
            'articles' => $article->orderBy('id''DESC')
            ->paginate(5),
            'pager' => $article->pager
        
];

echo 
view('panel/template'$data); 

<?php echo $pager->links('article', 'front_pagination');?>

it doesnt work to me, the error say "Call to member function links() on null" in view.