繁体   English   中英

MySQL 统计表中的行数 WHERE userid 等于? - 代码点火器

[英]MySQL Count rows From Table WHERE userid equals? - CodeIgniter

我在 CodeIgniter 中遇到 MySQL 问题,我有 3 列:

ID  |  USERID  |  NAME    |  MOBILE
1        1         JAMES      55
2        1         JOHN       66
3        2         ANNE       33

我想计算 CodeIgniter 中 USERID 为 1 的行数,有人可以帮助我吗?

我希望输出为 2,因为有 2 条记录分配给 USERID 1。

谢谢

$this->db->where('USERID',1);
$this->db->from('my_table');
echo $this->db->count_all_results();

尝试这个

select count(userid) from table where userid=1

CodeIgniter 模型

function count($userid){
    $this->db->select('*');
    $this->db->from('table_name');
    $this->db->where('userid',$userid);
   return  $this->db->get()->num_rows();
}

尝试这个

$query = $this->db->query('SELECT * FROM my_table where USERID = 1');
echo $query->num_rows(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM