Welcome Guest, Not a member yet? Register   Sign In
builder question when using pagination
#1

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

Please see the Pagination Documentation.

CodeIgniter $ Users Guide - Pagination - getPageCount()
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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.
Reply
#4

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

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB