Welcome Guest, Not a member yet? Register   Sign In
Pagination: or Why does AR class reset the query?

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:

constructQuery($args); // set up joins, selects, conditions etc
  $data['count'] = $db->count_all_records();
  $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?

there is a solution for that:

AR caching

Perfect. Many thanks.

Theme © iAndrew 2016 - Forum software by © MyBB