views:

3948

answers:

4

I'm very new to CodeIgniter and Active Record in particular, I know how to do this well in normal SQL but I'm trying to learn.

How can I select some data from one of my tables, and then count how many rows are returned using CodeIgniters Active Record class?

Thanks, Tom.

+5  A: 

Have a look at the result functions: http://codeigniter.com/user_guide/database/results.html

$this->db->from('yourtable');
[... more active record code ...]
$query = $this->db->get();
$rowcount = $query->num_rows();
Residuum
+4  A: 

AND, if you just want to get a count of all the rows in a table

$table_row_count = $this->db->count_all('table_name');
Zack
+3  A: 

Just gotta read the docs son!

$query->num_rows();

ascotan
The proper way to do it.
amr
A: 

how to count if wanna use join ?

joro