Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的分组计数导致数据库错误_Php_Mysql_Codeigniter - Fatal编程技术网

Php codeigniter中的分组计数导致数据库错误

Php codeigniter中的分组计数导致数据库错误,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有以下代码: public function date_range_customers($params){ $start_app_date = $params['start_app_date']; $end_app_date = $params['end_app_date']; $this->load->database(); $this->db->select( '

我有以下代码:

public function date_range_customers($params){

       $start_app_date = $params['start_app_date'];
       $end_app_date   = $params['end_app_date'];           


       $this->load->database();
       $this->db->select(
        'COUNT(tbl_appointment.id) AS total',            
        'tbl_customer.cus_name',
        'tbl_customer.cus_email',
        'tbl_customer.cus_mobile'
      );   
      $this->db->join('tbl_customer', 'tbl_customer.id = tbl_appointment.customer_id','inner');
      $this->db->join('tbl_transaction','tbl_transaction.app_id = tbl_appointment.id','inner');
      $this->db->where("app_date BETWEEN '$start_app_date' AND '$end_app_date' AND trans_type_id=1");
      $this->db->group_by('total','desc');
      $query = $this->db->get('tbl_appointment');
当我尝试按“总计”分组时,出现如下错误:

发生数据库错误错误错误号:1056无法在“total”上分组

tbl\u约会
internal中选择COUNT(tbl\u appointment.id)作为总计 加入
tbl\u客户
ON
tbl\u客户
id
=
tbl_约会
customer_id
internal JOIN
tbl_交易
ON
tbl\u交易
app\u id
=
tbl\u约会
id
其中
app\u日期
在“2018-01-01”和“2018-04-30”之间,以及
trans\u type\u id
=1组
总计

文件名:C:/wamp64/www/theme/system/database/DB_driver.php

电话号码:691


不应按聚合列进行分组

但您可能需要一份total desc的订单

   $this->load->database();
   $this->db->select(
    'COUNT(tbl_appointment.id) AS total',            
    'tbl_customer.cus_name',
    'tbl_customer.cus_email',
    'tbl_customer.cus_mobile'
  );   
  $this->db->join('tbl_customer', 'tbl_customer.id = tbl_appointment.customer_id','inner');
  $this->db->join('tbl_transaction','tbl_transaction.app_id = tbl_appointment.id','inner');
  $this->db->where("app_date BETWEEN '$start_app_date' AND '$end_app_date' AND trans_type_id=1");
  $this->db->group_by(array('cus_name','cus_email','cus_mobile'));     
  $this->db->order_by('total','desc');
  $query = $this->db->get('tbl_appointment');

为此,您应该在select中的非聚集列中添加group,请注意,在
$this->db->group by(['cus_name'、'cus_email'、'cus_mobile'])之前,您至少需要PHP5.4.0可以工作。否则,您需要将其替换为
$this->db->group_by(数组('cus_name'、'cus_email'、'cus_mobile')@RaymondNijland。。对的答案已更新为旧数组格式。许多的thanks@scaisEdge非常感谢..它工作得很好。但是当我试图在视图文件(Codeignator)、客户名称、客户电子邮件、客户电话displays中显示它作为未定义的索引时,我发现了问题。这里怎么了?我如何在视图中显示这些数据?用
$this->db->select('COUNT(tbl\u appointment.id))替换您的select语句总计,tbl_customer.cus_name,tbl_customer.cus_email,tbl_customer.cus_mobile',假)