Welcome Guest, Not a member yet? Register   Sign In
Pagination
#1

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!
Reply
#2

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.
Reply
#3

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);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB