【发布时间】:2016-11-14 17:18:55
【问题描述】:
我有一个mysql数据库,里面有3张表,一张叫fixturechannels,一张叫footballfixtures,一张叫satellite。
基本上,satellite table 包含有关卫星频道的信息(name、country、channelid), footballfixtures 包含(matchid、hometeam、awayteam、competition....),而 fixturechannels 是一个包含(matchid 和 channelid)的表,这些是分别由卫星和足球赛程表中的外键链接)。
以下是有关表格的更多详细信息:
我在下面使用了以下查询,它有效,我能够从表中回显我需要的详细信息
"SELECT * FROM fixturechannels INNER JOIN footballfixtures ON fixturechannels.matchid=footballfixtures.matchid INNER JOIN satellite ON fixturechannels.channelid=satellite.channelid";
用于回显细节的代码是:
<tbody><tr>
<th>Match ID</th>
<th>Home Team</th>
<th>Away Team</th>
<th>Competition</th>
<th>Date</th>
<th>Time</th>
<th>Channel ID</th>
<th>Channel Name</th>
</tr>
<?php foreach ($results as $res) { ?>
<tr>
<td><?php echo $res["matchid"]; ?></td>
<td><?php echo $res["hometeam"]; ?></td>
<td><?php echo $res["awayteam"]; ?></td>
<td><?php echo $res["competition"]; ?></td>
<td><?php echo $res["date"]; ?></td>
<td><?php echo $res["time"]; ?></td>
<td><?php echo $res["channelid"]; ?></td>
<td><?php echo $res["name"]; ?></td>
</tr>
我的问题是比赛详情显示两次 因为有两个频道被列为显示相同的匹配(见图)
我想要的输出是让每个匹配项的详细信息显示一次,显示匹配项的多个频道的名称显示在频道名称列中(没有多行)
我尝试使用 GROUP_CONCAT,但没有成功,我尝试了 GROUP_CONCAT,因为我知道不建议在 MYSQL 中为每个字段设置多个值。
非常感谢任何可以提供帮助或指导的人。
【问题讨论】:
-
请在您的问题中以文本形式发布表格
标签: mysql database inner-join group-concat