codeigniter - Code Igniter - remove single quotes from where_in -


i have 2 queries:

$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 strgenrename')                                 ->from('tbltracks')                                 ->join('tblgenres', 'tbltracks.intgenreid = tblgenres.intgenreid', 'left')                                 ->where_in('tbltracks.intgenreid', $genres->strdjgenres)                                 ->get()                                 ->result(); 

the first query returning string such

'1,2,3,4,8,6,5,7,45,66'

which using in where_in clause on second query. issue string, writing sql like:

select `tbltracks`.*, `tblgenres`.`strname` strgenrename (`tbltracks`) left join `tblgenres` on `tbltracks`.`intgenreid` = `tblgenres`.`intgenreid` `tbltracks`.`intgenreid` in ('1,2,3,4,8,6,5,7,45,66')  

with quote around it, treated single value. how can second query perform how want it? ie

.... `tbltracks`.`intgenreid` in (1,2,3,4,8,6,5,7,45,66)  

multiple values can passed where_in clause array.


the quotes start , end of string can removed using trim():

$dj_genres = trim($genres->strdjgenres, "'"); 

this string can converted array of strings, pass where_in clause of second query.

$dj_genres_array = explode(",", $dj_genres); 

or, if need array of integers:

$dj_genres_int_array = array_map('intval', $dj_genres_array); 

you can add resultant array second query:

// ...     ->where_in('tbltracks.intgenreid', $dj_genres_array) // ... 

or:

// ...     ->where_in('tbltracks.intgenreid', $dj_genres_int_array) // ... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -