CodeIgniter Forums

Full Version: Count how many users there are
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

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

El Forum

[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!

El Forum

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

Code:
$query->num_rows();

El Forum

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

Thanks!

El Forum

[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.

El Forum

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

Keep up the good work