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:

Total:

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(e.id) as id, e.color, GROUP_CONCAT(e.S) as small FROM  #__bl_equipment as e WHERE e.type = 4 AND e.t_id = 2606";
       $db->setQuery($query);
    $equip1 = $db->loadObjectList();


<table>

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

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

?>


</table>

Only result I have been able to get:

Black DNA 1, 2, 3

Leave a Reply

*

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