CodeIgniter Forums
Pagination - 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 (/showthread.php?tid=78920)



Pagination - Llui7 - 03-27-2021

Hello I have a problem with paging the results of a query, I have read the documentation for codeigniter4 pagination,

But they show how to paginate the results of all the data in a table. I don't know how to paginate the results of a query. 
Can you help me?

Controller:

Quote:    public function index()
    {  
$TecnicsModel = new TecnicsModel();    
$published=1;
$data['results']= $TecnicsModel->result_published($published);
return view('views/view.php');
    }



Model:
 
Quote:   public function result_published($published)
    {
    $query = "SELECT  * FROM table WHERE Published = $published";   
    $query=$this->db->query($query);
    return $query->getResultArray();
    }



View

Quote:<?= $pager->links() ?>




Thanks!


RE: Pagination - iRedds - 03-27-2021

1. You are not calling the paginate() method
2. You are not using Services::pager()
3. You do not passed data to the view.
4. Your code doesn't even come close to the code from the documentation.

What result do you expect?

5. Model pagination only works with shared query builder.


RE: Pagination - IvanBell - 03-28-2021

If the table is specified in your model, I believe you can put this code in the controller and get the same result:
$data['results'] = $TecnicsModel->where('published', 1)->paginate($number_of_results_per_page);