Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Count rows From Table WHERE userid equals? - CodeIgniter

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

like image 275
gloriaside Avatar asked May 23 '26 18:05

gloriaside


1 Answers

$this->db->where('USERID',1);
$this->db->from('my_table');
echo $this->db->count_all_results();
like image 119
Kanishka Panamaldeniya Avatar answered May 26 '26 07:05

Kanishka Panamaldeniya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!