我codeigniter-mysql
需要选择要从table_2
中连接的值,table_1
并且需要在逗号分隔的字段值中应用 where 语句。尝试如下,
$where = $this->db->escape("FIND_IN_SET(table_1.id,table_2.places_id)<>0");
$this->db->select('table_2.*,GROUP_CONCAT(table_1.location)AS location');
$this->db->from('table_2');
$this->db->join('table_1', $where);
$this->db->where('ltable_2.packages_id', $id);
$results = $this->db->get();
return $results->result();
但是上面的codeigniter db对象返回以下mysql查询并且它不起作用:(
SELECT `table_2`.*, GROUP_CONCAT(table_1.location)AS location FROM `table_2` JOIN `table_1` ON 'FIND_IN_SET(table_1.id,table_2.places_id)<>0' WHERE `ltable_2`.`packages_id` = <id-goes-here>
似乎周围的引号'FIND_IN_SET(table_1.id,table_2.places_id)<>0'
造成了问题!感谢所有帮助以解决问题。