dongqu3623 2015-02-14 05:41
浏览 35
已采纳

CodeIgniter COUNT有活动记录吗?

I am working in codeigniter.. I want to count the no. of rows having the same order_no.. below is my code.

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();
    }

Pls help..

  • 写回答

3条回答 默认 最新

  • dougu3290 2015-02-14 05:50
    关注

    Try changing your select line to look like this:

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

    Rather than having all fields accessible like they currently are, you will instead only have access to one variable called count. To keep all variables accessible and add the count in as well, use this instead:

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

    Feel free to change the lowercase name for count, I'm just using that as an example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?