猿问

目前我得到了我的查询结果,但我想获得记录数

我想以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 条记录。


千万里不及你
浏览 193回答 3
3回答

肥皂起泡泡

试试这个 模型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();        }

GCT1015

获得计数的多种方法1 . echo count($query->result()); 2 . echo $query->num_rows();3 . You can use `count(*)` in `select` statement

慕莱坞森

要获取获取的记录数,$data = $query->result();echo count($data); // use this as per your requirementsreturn $data;
随时随地看视频慕课网APP
我要回答