1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
我相信這應(yīng)該有效 - 我對(duì)您的查詢(xún)進(jìn)行了調(diào)整。當(dāng)您對(duì)查詢(xún)的左側(cè)(匹配項(xiàng))感興趣并且不關(guān)心俱樂(lè)部是否未填充時(shí),您可以使用左連接。F ex 如果您有主客場(chǎng) 1 和 5。我們知道 1 是阿森納,但在俱樂(lè)部中沒(méi)有 5 的條目。Left join 會(huì)顯示它,inner join 不會(huì)。
<?php
$sql = "SELECT home,away,homeclub.name as homename,awayclub.name as awayname FROM matches
JOIN clubs as homeclub ON matches.home = homeclub.id
JOIN clubs as awayclub ON matches.away = awayclub.id"
$rs_result = $conn->query($sql);
?>
<div style="overflow-x:auto">
<table>
<tr><th><strong>Home</strong></th><th><strong>Away</strong></th><tr>
<?php
while($row = $rs_result->fetch_assoc()) {
?>
<tr>
<td><a href="club.php?id=<?php echo $row['home'];?>"><? echo $row['homename']; ?></a></td>
<td><a href="club.php?id=<?php echo $row['away'];?>"><? echo $row['awayname']; ?></a></td>
</tr>
<?php } ?>
</table>
</div>
- 1 回答
- 0 關(guān)注
- 92 瀏覽
添加回答
舉報(bào)