2013-10-21 49 views
0

我想一些成績合併爲1臺,不好的就是沒有獨特的鍵來標識它,這是我的MySQL表中的數據: -相結合,在PHP中顯示結果MYSQL

ServiceGroup Name  Moperator   ShortCode 
-------------- --------- ----------------- --------- 
INTEGRAT  norman  KW_DTAC   11111    
KW_I2C   norman  KW_ZAIN   00000    
AB_MK   norman  HUT/TRUEMOVE  4541311   
INTERGRAT  amanda  KW_DTAC   11111  

在表中列出的名稱amanda和norman具有相同的值,但是我希望結果在PHP上顯示爲這樣。

ServiceGroup Name    Moperator   ShortCode 
-------------- ---------   ----------- --------- 
INTEGRAT  norman,amanda  KW_DTAC   11111    
KW_I2C   norman   KW_ZAIN   00000    
AB_MK   norman   HUT/TRUEMOVE  4541311  

我應該怎麼把它放在PHP上,查詢應該是什麼樣子?這是我的例子查詢: -

SELECT Distinct userfilters.ServiceGroup, userdetails.Login, userfilters.Moperator, userfilters.ShortCode FROM userdetails INNER JOIN userfilters ON userfilters.UserDetailsID=userdetails.UserDetailsID AND Login IN ('amanda', 'brandon', 'bryan', 'christina', 'johnny', 'larry', 'monica', 'norman', 'eko') ORDER BY ServiceGroup DESC 

回答

0

集團以獨特的列中的數據,並使用grop_concat把登錄在逗號分隔列表

SELECT f.ServiceGroup, 
     group_concat(d.Login) as logins, 
     f.Moperator, 
     f.ShortCode 
FROM userdetails d 
INNER JOIN userfilters f ON f.UserDetailsID = d.UserDetailsID 
WHERE d.Login IN ('amanda', 'brandon', 'bryan', 'christina', 'johnny', 'larry', 'monica', 'norman', 'eko') 
GROUP by f.ServiceGroup, f.Moperator, f.ShortCode 
ORDER BY f.ServiceGroup DESC 
+0

不錯!那麼我如何在PHP中迴應結果呢? – Furry

+1

來吧@Furry,我認爲你可以谷歌:循環結果集http://php.net/manual/en/function.mysql-fetch-assoc.php或http://php.net/manual/ en/mysqli-result.fetch-assoc.php –

+0

我找到了解決方案,我需要將其聲明爲SOMETHING,以便結果出來。謝謝! – Furry