Welcome Guest, Not a member yet? Register   Sign In
Count how many users there are
#1

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

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

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

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

Code:
$query->num_rows();
#5

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

Thanks!
#6

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

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

Keep up the good work




Theme © iAndrew 2016 - Forum software by © MyBB