CodeIgniter COUNT 有活动记录吗?

3 php arrays codeigniter

我在 codeigniter 工作..我想数数。具有相同 order_no 的行.. 下面是我的代码。

public function get_my_orders() {
        $user_data = $this->session->all_userdata();
        $email = $user_data['user_email'];
            $this->db->select('*');
            $this->db->from('order_details');
            $this->db->where('email', $email);
            $this->db->group_by('order_no');
            $this->db->order_by('order_no', 'DESC');
            $query = $this->db->get();
            return $query->result();
    }
Run Code Online (Sandbox Code Playgroud)

请帮助..

Sha*_*lam 5

您可以使用$this->db->count_all_results()

 public function get_my_orders() {
    $user_data = $this->session->all_userdata();
    $email = $user_data['user_email'];
        //$this->db->select('*');// no need select as you only want counts
        $this->db->from('order_details');
        $this->db->where('email', $email);
        //$this->db->group_by('order_no');//no need group_by as you only want counts
        //$this->db->order_by('order_no', 'DESC');//no need order_by as you only want counts            
        return $this->db->count_all_results();;
}
Run Code Online (Sandbox Code Playgroud)