我正在尝试从mysql数据库中创建编码json并使用CodeIgniter连接表,但我想将相同的数据组合成一个发生了group_by错误的数据。有什么问题?
错误提醒
SELECT列表的表达式#1不在GROUP BY子句中,并且包含非聚合列'project.mytb1.id',它在功能上不依赖于GROUP BY子句中的列;这与sql_mode = only_full_group_by
不兼容
我的剧本
function get_idCode() {
$keyword = $this->uri->segment(3);
$data = $this->db->from('mytb1')
->join('mytb2', 'mytb2.id = mytb1.id')
->like('mytb1.id',$keyword)
->group_by('mytb1.id')
->get();
foreach($data->result_array() as $row)
{
$arr['query'] = $keyword;
$arr['suggestions'][] = array(
'value' =>$row->id,
'name' =>$row->name
);
}
echo json_encode($arr);
}
答案 0 :(得分:2)
试试这个
$data = $this->db->select('*') # added
->from('mytb1') # changed
->join('mytb2', 'mytb2.id = mytb1.id')
->like('mytb1.id',$keyword)
->group_by('mytb1.id')
->order_by('mytb1.id', 'ASC') # added
->get();