2

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'造成了问题!感谢所有帮助以解决问题。

4

1 回答 1

1

你可以试试$this->db->join('table_1', $where, false);。那将摆脱引号,否则您的查询很好,应该没问题。

于 2015-09-11T08:55:49.367 回答