Welcome Guest, Not a member yet? Register   Sign In
Why does active record count_all_results() is calling _reset_select() ?
#11

[eluser]Aken[/eluser]
Just trying to provide an option for recreating queries without duplicating your code. Like I said, it's not ideal.

I agree that an addition for including the total rows regardless of limit/offset would be a good addition. You should add a feature request to the Github repository requesting this. There's a few ways that could go about it - all of which would need to keep backwards compatibility in mind (don't want to break any current apps).
#12

[eluser]skunkbad[/eluser]
If you look at the _do_user_records_query() method in my user model, then you can see how I did it:

bitbucket.org/skunkbad/community-auth-ci-session-version/src/6ae0d164035d/application/helpers/MY_url_helper.php/user_model.php

Two other methods are calling that method, and in other (newer) projects that I am working on, there is only one method. Easy stuff.
#13

[eluser]the_yk[/eluser]
If I understand your problem correctly, maybe what you need is Active Record Caching

Code:
$this->db->start_cache();
$this->db->where('id > 100');
$this->db->stop_cache();

$total_result = $this->db->count_all_results('table_name');
// it'll give you the number of result, equivalent with
// SELECT COUNT(*) FROM table_name WHERE id > 100

$result_set = $this->db->get('table_name', 10, 0)->result(); //Limit: 10, Offset: 0
// it'll give you the result set, equivalent with
// SELECT * FROM table_name WHERE id > 100 LIMIT 0,10 (in MySQL)

see how WHERE clause is cached.

If you want to know how many records you get in result set, simply use count
Code:
$num_result = count($result_set);

Dont forget to flush the cache when you're done with it, otherwise, it'll mess with your other query.

Code:
$this->db->flush_cache();
#14

[eluser]InsiteFX[/eluser]
And what is wrong with this to create your own calls?

CodeIgniter Users Guide - Custom Function Calls
#15

[eluser]bientek[/eluser]
the_yk, thanks for your post. This ended up being the most elegant solution to my problem of having to repeat the query after running count_all_results().




Theme © iAndrew 2016 - Forum software by © MyBB