CodeIgniter Forums
Count how many users there are - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Count how many users there are (/thread-2163.html)



Count how many users there are - El Forum - 07-19-2007

[eluser]jtotheb[/eluser]
hi,

i would like to use active record to build a select query, and then return the volume of that query in my view.

I wish to show how many users are registered in something i am practicing building with CI!

I tried using mysql_num_rows but that didn't work!

Any help would be very gratefully received.


Count how many users there are - El Forum - 07-19-2007

[eluser]Phil Sturgeon[/eluser]
Code:
echo count($query->result_array());



Count how many users there are - El Forum - 07-19-2007

[eluser]jtotheb[/eluser]
That's great!

Thank you very much indeed, i did see count somewhere but didn't think of trying it.

Thanks again!


Count how many users there are - El Forum - 07-19-2007

[eluser]Glen Swinfield[/eluser]
You can also use:

Code:
$query->num_rows();



Count how many users there are - El Forum - 07-19-2007

[eluser]jtotheb[/eluser]
Which is quicker?

Thanks!


Count how many users there are - El Forum - 07-19-2007

[eluser]Glen Swinfield[/eluser]
In terms of processing time? It's negligible unless you are using it thousands of times. Basically a CI num_rows() function calls mysql_num_rows() eventually I would think - or could in fact call count($query->result_array()) anyway. I've never really looked through the DB files to see exactly what goes on, but generally the fewer function calls the quicker it is.

But don't get too hung up on it because it will be the database itself that slows your apps down, not a few extra function calls.


Count how many users there are - El Forum - 08-02-2007

[eluser]Unknown[/eluser]
thanks a million for this!!!

Keep up the good work