亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

目前我得到了我的查詢結果,但我想獲得記錄數

目前我得到了我的查詢結果,但我想獲得記錄數

PHP
千萬里不及你 2022-01-02 17:22:21
我想以count一個數字獲取我的查詢,目前它顯示所有記錄控制器: public function fetchCounts(){    $Result = $this->receivedModel->vehicleFreight($this->session->userdata('user_branch'));    }模型:public function vehicleFreight($branch_id)          {               $this->db->select('*');             $this->db->from('truck_freight');             $this->db->where('truck_freight_status','truck_freight');             $this->db->where('fr_memo_to',$branch_id);            $query = $this->db->get();            return $query->result();        }  我如何count()在我的查詢中使用。在我的數據庫中,我有 3 條記錄。
查看完整描述

3 回答

?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

試試這個 模型


public function vehicleFreight($branch_id)  

        {  

             $this->db->select('count(*)');

             $this->db->from('truck_freight');

             $this->db->where('truck_freight_status','truck_freight');

             $this->db->where('fr_memo_to',$branch_id);


            $query = $this->db->get();

            return $query->result();

        }


查看完整回答
反對 回復 2022-01-02
?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

獲得計數的多種方法


1 . echo count($query->result()); 



2 . echo $query->num_rows();


3 . You can use `count(*)` in `select` statement


查看完整回答
反對 回復 2022-01-02
?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

要獲取獲取的記錄數,


$data = $query->result();

echo count($data); // use this as per your requirements

return $data;


查看完整回答
反對 回復 2022-01-02
  • 3 回答
  • 0 關注
  • 175 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號