![]() |
How to get total records from Pager - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to get total records from Pager (/showthread.php?tid=83124) |
How to get total records from Pager - frocco - 09-22-2022 Hello, I have a Product model that I perform a where search and then paginate the results. If I use the countAllResults, I get an incorrect number of records found. Is there a way to count all records returned? RE: How to get total records from Pager - captain-sensible - 09-22-2022 i used this approach to count entries in a db: Code: $query = $builder->where('category',$category)->countAllResults(); RE: How to get total records from Pager - frocco - 09-22-2022 (09-22-2022, 10:46 AM)captain-sensible Wrote: i used this approach to count entries in a db: I am using the Codeigniter 4 Model, would this still work or do I have to change to the builder class? Thanks RE: How to get total records from Pager - captain-sensible - 09-23-2022 had a quick look through some previous code of mine and found this: Code: It was when i was playing with a web for my daughter, fashion web. now i coudn't find the code for the method isEmptyMens(); its one of my model->method names and will most certainly contain contain stand model methods for geting data , and in the docs also what I can say is that Code: $handle= new PortfolioModel(); way now to use CodeIgniter Model to get a Count. But i've i have shown using some lateral thinking you can get a count using CodeIgniter Model class and its methods. In later code i just thought horses fore courses and just switched to Query builder to get the job done. RE: How to get total records from Pager - frocco - 09-23-2022 (09-23-2022, 02:13 AM)captain-sensible Wrote: had a quick look through some previous code of mine and found this: Thanks for getting back to me. The only way I found is to use two result sets based on same filtered query. $result->like('cat_title', trim($locate) . '%'); $result2->like('cat_title', trim($locate) . '%'); $results2 = $result2->countAllResults(); $results = $result->paginate(5); RE: How to get total records from Pager - frocco - 09-23-2022 I just realized that $this->model->pager->getTotal() returns the correct count. duh |