我有兩個表(匹配,團隊)。在比賽表中,我有id,team1,team2(其中team1和team2是球隊的ID)。在team表中我有id和name ..我如何在php中打印比賽結果,但是顯示球隊名稱而不是他們的ID?內部加入PHP
我的代碼(印刷只teamid VS teamid):
<?php
require_once 'conf/conf.php';
require_once 'functions.php';
$query = mysql_query("SELECT time1 as t1id, time2 as t2id
FROM matches
INNER JOIN teams
ON
teams.id = matches.time1
");
//echo mysql_num_rows($query);
while ($row = mysql_fetch_assoc($query))
{
$t1 = $row["t1id"];
$t2 = $row["t2id"];
echo ($t1 . " vs. " . $t2 . "<br>");
}
?>
'var_dump($ row)'應該回答你的問題。 –
使用索引和別名連接表兩次。 – rishta