如何显示clubI homeD和club questID,显示home clubName和quest clubName。它现在可以正常显示正确的俱乐部ID,但如何显示名称ClubName。 我的数据库中的表:
clubs (clubID, clubName)
matches (matchesID, homeID, questID, homeGoals, questGoals)
<?php
$result = $conn->prepare(
"SELECT
m.matchesID
hc.clubName as homeClub,
gc.clubName as guestClub,
m.homeGoals,
m.guestGoals
FROM matches AS m
JOIN clubs AS hc ON hc.clubID = m.homeID
JOIN clubs AS gc ON gc.clubID = m.guestID ORDER BY matchesID ASC");
$result->execute();
$results = $result->fetchAll();
foreach ($results as $index => $row){
?>
<tr>
<td><label><?php echo $row['matchID']; ?></label></td>
<td><label><?php echo $row['homeClub']; ?></label></td>
<td><label><?php echo $row['guestClub']; ?></label></td>
<td><label><?php echo $row['homeGoals']; ?> : <?php echo $row['guestGoals']; ?></label></td>
</tr>
<?php } ?>
答案 0 :(得分:0)
如果我正确地阅读了您的问题,那么这可能会有效
$result = $conn->prepare(
"SELECT
m.matchesID
hc.clubName as homeClub,
gc.clubName as guestClub,
m.homeGoals,
m.guestGoals
FROM matches AS m
JOIN clubs AS hc ON hc.clubID = m.homeID
JOIN clubs AS gc ON gc.clubID = m.guestID ORDER BY matchesID ASC");
$result->execute();
$results = $result->fetchAll();
foreach ($results as $index => $row){
?>
<tr>
<td><label><?php echo $row['matchesID']; ?></label></td>
<td><label><?php echo $row['homeClub']; ?></label></td>
<td><label><?php echo $row['guestClub']; ?></label></td>
<td><label><?php echo $row['homeGoals']; ?> : <?php echo $row['guestGoals']; ?></label></td>
</tr>