CodeIgniter Forums
builder question when using pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: builder question when using pagination (/showthread.php?tid=83467)



builder question when using pagination - frocco - 09-28-2022

I created a builder object and if I use the where function to restrict results, how do I get the total records for pagination links?

I seem to have to create two builder objects

Code:
$builder = $this->db->table('searchlogs');
$builder2 = $this->db->table('searchlogs');

$builder->where('id' > 5);
$builder2->where('id' > 5);
$result = $builder->get(5,10);
$total = $builder2->countAllResults();

I cannot use countAllResults with $builder as this kills the filter returned.


RE: builder question when using pagination - InsiteFX - 09-29-2022

Please see the Pagination Documentation.

CodeIgniter $ Users Guide - Pagination - getPageCount()


RE: builder question when using pagination - frocco - 09-30-2022

(09-29-2022, 12:35 AM)InsiteFX Wrote: Please see the Pagination Documentation.

CodeIgniter $ Users Guide - Pagination - getPageCount()

I got this working using the same builder object, I had to assign the where condition again and issue the countAllResults.

I ended up putting it in a function to not repeat code.


RE: builder question when using pagination - InsiteFX - 10-01-2022

Glad you got it working. I use the above code in the Pagination template to show ( Page 1 of 10 Total Pages ).