Welcome Guest, Not a member yet? Register   Sign In
Serious Count Rows Problem
#1

[eluser]Davcon[/eluser]
Hi,

On the CI user guide we are told that the way to count the number of results generated by a query is:

$this->db->count_all_results();


However, I've noticed lately that the (count) results I've been getting back from those queries aren't accurate. I've also noticed that some people are using:

$query->num_rows();

...to find out the number of rows generated by a query.



Interestingly the $query->num_rows() method does not appear to be mentioned on the active record part of the user guide. However, it does produce accurate results.

So, this is really a request for clarification. I have a bunch of questions:

1. Have I misunderstood what the purpose of db->count->all_results() is?

2. What is the "proper" method of counting rows of results using Active Record?

3. How come the num->rows() method doesn't appear to get a mention in the user guide?

Thank you so much.
#2

[eluser]osci[/eluser]
As of mentioning it is here
#3

[eluser]Davcon[/eluser]
Thank you so much.

That page you gave a link to was very helpful. Interestingly, the page is hidden within the inner bowels of the manual. It's not on the index page (the page that comes up when you click the fancy pull down button) and finding the page is a bit tricky. I have to also highlight the fact that num->rows() does not get a mention in the active record page of the user guide which is, I think, a more obvious place to look.

Clearly I have to be grateful to the makers of Codeigniter for building the framework and for making all of this possible - absolutely free of charge. So, please let me stress that I am very grateful and I am humble.

At first I thought my original question was stupid. However, now I'm not so sure if it was a stupid question after all.

Thanks again for your help!
#4

[eluser]osci[/eluser]
Comsidering the placement I consider it rather simple.
First of all I didn't read only about AR in user_guide.
It's placement is under Database as is AR. You didn't have trouble finding about AR right?

About the other questions
count_all_results to be accurate with your AR query has to be supplied the same restrictions.

num_rows return the rows of the last query (last run)

Proper method depends on user likes I guess.
#5

[eluser]InsiteFX[/eluser]
Hi David,

Not a stupid question, num_rows you can use with Active Record. Matter of fact you can use any of the query results with active Record.
The Query results are are more like helper functions that why then have there own topic on the subject.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB