具有活动记录的CodeIgniter COUNT? [英] CodeIgniter COUNT with active record?

查看:67
本文介绍了具有活动记录的CodeIgniter COUNT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

请帮助。

推荐答案

尝试更改您的选择行,使其看起来像这样:

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');

可以随意更改 count ,我只是以它为例。

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

这篇关于具有活动记录的CodeIgniter COUNT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆