簡體   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