2017-01-04 118 views
2

我用笨的我的项目,这是我在模型集团通过与笨

public function group_all_ville(){ 
     $this->db->select('*'); 
     $this->db->from('departement'); 
     $this->db->join('villes', 'villes.num_dept = departement.num_dept'); 
     $this->db->group_by('nom_dept'); 
     $query = $this->db->get(); 
     return $query->result(); 
    } 

代码,这是执行后错误

A Database Error Occurred 

Error Number: 1055 

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'pneu.departement.id_dept' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 

SELECT * FROM `departement` JOIN `villes` ON `villes`.`num_dept` = `departement`.`num_dept` GROUP BY `nom_dept` 

Filename: C:/wamp64/www/pneu/system/database/DB_driver.php 

Line Number: 691 

我尝试不同的方法,但没有结果。由于

回答

1

使用order_by条款以及

$this->db->group_by('nom_dept'); 
$this->db->order_by('nom_dept', 'asc'); # or desc 

FYI:设置SQL模式和会话集不能解决实际的错误。

例子(最好不要做

  1. https://stackoverflow.com/a/35729681/4595675
0

谢谢回答,我找到解决办法:

$this->db->select('d.nom_dept'); 
$this->db->from('departement AS d, villes as v'); 
$this->db->where('v.num_dept = d.num_dept'); 
$this->db->group_by('d.nom_dept'); 

这里指的更多的infromation

<a href="http://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html" target="_blank">Here</a>