我有 2 个查询:
$genres = $this->db->select('Group_Concat(intGenreId) strDJGenres')
->from('tblDJGenres')
->where('intDJId', $this->session->userdata('non_admin_userid'))
->get()
->row();
$results = $this->db->select('tblTracks.*, tblGenres.strName as strGenreName')
->from('tblTracks')
->join('tblGenres', 'tblTracks.intGenreId = tblGenres.intGenreId', 'left')
->where_in('tblTracks.intGenreId', $genres->strDJGenres)
->get()
->result();
第一个查询返回一个字符串,例如
'1,2,3,4,8,6,5,7,45,66'
我在第二个查询的 where_in 子句中使用它。问题是使用这个字符串,它正在编写如下 SQL:
SELECT `tblTracks`.*, `tblGenres`.`strName` as strGenreName FROM (`tblTracks`) LEFT JOIN `tblGenres` ON `tblTracks`.`intGenreId` = `tblGenres`.`intGenreId` WHERE `tblTracks`.`intGenreId` IN ('1,2,3,4,8,6,5,7,45,66')
使用引号将其视为单个值。我怎样才能得到第二个查询来执行我想要的呢?IE
.... where `tblTracks`.`intGenreId` IN (1,2,3,4,8,6,5,7,45,66)