我想以数字显示当前所有记录的查询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条记录。
答案 0 :(得分: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();
}
答案 1 :(得分:2)
许多计数方法
1 . echo count($query->result());
2 . echo $query->num_rows();
3 . You can use `count(*)` in `select` statement
答案 2 :(得分:1)
要获取提取的记录数,
$data = $query->result();
echo count($data); // use this as per your requirements
return $data;
答案 3 :(得分:1)
您可以使用以下函数返回结果数。
return $this->db->count_all_results();
应使用它代替get()
$query = $this->db->get();
答案 4 :(得分:1)
如下更改代码:
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName STR3598C -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$disk.Size
$disk.FreeSpace