我已成功设法选择并返回具有相关成员的团队。在成员表中有以下列:score_1, score_2
等......
我正在努力将这些整数值从表格中取出来与数据并列:
<?php
$sql = "SELECT t.team_name as team_name, GROUP_CONCAT(m.firstName, ' ', m.lastName) as team_members
FROM members AS m
JOIN team_members AS tm
ON tm.member_id = m.member_id
JOIN teams as t
on t.team_id = tm.team_id
WHERE t.dashboard_id = $dashboard_id AND t.team_id = $teamSelect
GROUP BY t.team_name";
if(!$result = $conn->query($sql)) {
// die(printf("Errormessage: %s\n", $conn->error));
}
while($row = $result->fetch_assoc()){
echo '<h2>Team Scores: <span class="teamNameTable">' . $row["team_name"] . '</span></h2><br>';
$names = explode(',', $row['team_members']);
echo '<div class="tableHeader">';
echo '<div class="col">Name</div>';
echo '<div class="col">SDO</div>';
echo '<div class="col">DCTO</div>';
echo '<div class="col">ED</div>';
echo '<div class="col">CA</div>';
echo '<div class="col">DHPT</div>';
echo '<div class="col">IRT</div>';
echo '<div class="col">GL</div>';
echo '<div class="col">IL</div>';
echo '</div>';
foreach($names as $name) {
echo '<div class="teamNameMember">' . $name . '</div>';
}
echo '<br>';
}
?>
更新
foreach($names as $name) {
echo '<div class="teamNameMember">' . $name . '</div>';
}
echo '<br>';
}
答案 0 :(得分:0)
您忘了将这些列添加到您的选择语句...
$sql = "SELECT t.team_name as team_name, GROUP_CONCAT(m.firstName, ' ', m.lastName) as team_members, m.score_1, m.score_2
FROM members AS m
JOIN team_members AS tm
ON tm.member_id = m.member_id
JOIN teams as t
on t.team_id = tm.team_id
WHERE t.dashboard_id = $dashboard_id AND t.team_id = $teamSelect
GROUP BY t.team_name";