Reputation: 51
I am having trouble with MySQL in CodeIgniter, I have the 3 columns:
ID | USERID | NAME | MOBILE 1 1 JAMES 55 2 1 JOHN 66 3 2 ANNE 33
I want to count the number of rows where the USERID is 1 in CodeIgniter, anyone can help me?
I expect the output will be 2, because there is 2 records assigned to the USERID 1.
Thanks
Upvotes: 3
Views: 7943
Reputation: 26
CodeIgniter Model
function count($userid){
$this->db->select('*');
$this->db->from('table_name');
$this->db->where('userid',$userid);
return $this->db->get()->num_rows();
}
Upvotes: 0
Reputation: 17576
$this->db->where('USERID',1);
$this->db->from('my_table');
echo $this->db->count_all_results();
Upvotes: 4
Reputation: 3975
Try this
$query = $this->db->query('SELECT * FROM my_table where USERID = 1');
echo $query->num_rows();
Upvotes: -1