如何显示而不是clubI homeD和club questID,而是显示主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 } ?>

最佳答案

如果我正确阅读了您的问题,则可能有效

$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>

关于php - 在运动数据库中关联表格。赛程表-主俱乐部和客场俱乐部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50405169/

10-11 10:36