I am having trouble with MySQL in CodeIgniter, I have the 3 columns:
我在CodeIgniter的MySQL有问题,我有3列:
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?
我想计算USERID在CodeIgniter中为1的行数,有人能帮我吗?
I expect the output will be 2, because there is 2 records assigned to the USERID 1.
我希望输出是2,因为有2条记录被分配给USERID 1。
Thanks
谢谢
3 个解决方案
#1
4
$this->db->where('USERID',1);
$this->db->from('my_table');
echo $this->db->count_all_results();
#2
0
try this
试试这个
select count(userid) from table where userid=1
#3
-1
Try this
试试这个
$query = $this->db->query('SELECT * FROM my_table where USERID = 1');
echo $query->num_rows();
#1
4
$this->db->where('USERID',1);
$this->db->from('my_table');
echo $this->db->count_all_results();
#2
0
try this
试试这个
select count(userid) from table where userid=1
#3
-1
Try this
试试这个
$query = $this->db->query('SELECT * FROM my_table where USERID = 1');
echo $query->num_rows();