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条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了