MYSQL query multiple comma separated strings

I have data stored in MYSQL database as shown below:

 id    t_id     type    color       Y        S       M          L   
  2    2606      2    Black DNA   1,5,8    4,2,6    7,3,9    10,11,12   

I want the query to return like this with PHP:


Black DNA

1 (Y)  
2 (S)  
3 (M)  
4 (S)  
5 (Y)  
6 (S)  
7 (M)  
8 (Y)  
9 (M)  
10 (L)  
11 (L)  
12 (L)  

I am using Joomla 2.7, Here is what I have tried in PHP:

$query = "SELECT DISTINCT( as id, e.color, GROUP_CONCAT(e.S) as small FROM  #__bl_equipment as e WHERE e.type = 4 AND e.t_id = 2606";
    $equip1 = $db->loadObjectList();


<?php foreach($this->equip1 as $equip){

echo '<tr><td>';
echo $equip->color;
echo '</td><td>';
echo $equip->small;
echo '</td></tr>';}



Only result I have been able to get:

Black DNA 1, 2, 3

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.