MYSQL查询多个逗号分隔的字符串

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

查看全部
doudou130216
doudou130216
2012/11/22 17:39
  • csv
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复