CodeIgniter Forums
Pagination: or Why does AR class reset the query? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Pagination: or Why does AR class reset the query? (/showthread.php?tid=13152)



Pagination: or Why does AR class reset the query? - El Forum - 11-12-2008

[eluser]steward[/eluser]
Suppose I build a complex SQL SELECT from a search form.

I will need to call db->count_all_results() so I have that value for pagination.
I will also need to get the results db->get().

Using either of these methods resets the query. So it must be constructed again.

Okay, I'll create a function to build the query:

Code:
constructQuery($args); // set up joins, selects, conditions etc
  $data['count'] = $db->count_all_records();
  constructQuery($args);
  $data['query'] = $db->get();

Seems to me the database might have an option NOT to reset the query after a count.
Or. I am way out in left field. Maybe I should not be using the AR class.
Which kinda makes sense, as there is no "active" record, this is a search/browse.

The context of this question is pagination. I am porting from a different system which sent the query directly into the pagination system as a last step. The queries (count and get) actually took place in the pagination class.

The pagination I wish to use is different from CI as it provides more info, and allows the user to enter a page number (jump to page). That may simply be my issue.

Noob here. Any comments?


Pagination: or Why does AR class reset the query? - El Forum - 11-12-2008

[eluser]barbazul[/eluser]
there is a solution for that:

AR caching


Pagination: or Why does AR class reset the query? - El Forum - 11-12-2008

[eluser]steward[/eluser]
Perfect. Many thanks.