drzfz9995 2014-04-02 19:12
浏览 34
已采纳

在表中列出结果 - 同时在TD中循环和列表结果

I have tried to find the answer for this but having no joy. I have a while loop that gives me numerous rows outputted in a table. It's here:

$result = mysqli_query($con,"SELECT a.winner AS horseWinner, a.twitter_pubstatus,
a.market, a.racetime, a.racecourse, a.date_dd, a.date_mm, b.username, b.course, 
b.horse,b.type, b.racetime, b.dd, b.mm FROM results a 
INNER JOIN bets b ON a.winner = b.horse WHERE a.twitter_pubstatus = 0 
AND a.market = '$win' AND b.type = '$userwin' 
AND a.date_dd = b.dd AND a.date_mm = b.mm GROUP BY a.winner");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['horseWinner'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
echo "</table>";

This is all well and good but the issue lies that there is more than one username that is per horseWinner. I have tried to do another while loop within a while loop. So I would like it to list the usernames in the second column seperated by comma.

Many thanks

  • 写回答

1条回答 默认 最新

  • doushi3819244 2014-04-02 19:20
    关注

    Add a GROUP_CONCAT() on your username so that it returns a comma separated list -

    SELECT a.winner AS horseWinner, a.twitter_pubstatus,
    a.market, a.racetime, a.racecourse, a.date_dd, a.date_mm, 
    
    GROUP_CONCAT(b.username) as username, 
    
    b.course, b.horse,b.type, b.racetime, b.dd, b.mm FROM results a 
    INNER JOIN bets b ON a.winner = b.horse WHERE a.twitter_pubstatus = 0 
    AND a.market = '$win' AND b.type = '$userwin' 
    AND a.date_dd = b.dd AND a.date_mm = b.mm GROUP BY a.winner
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染