我有這兩個表,我想從第二個表中爲第一個表中的兩個外鍵獲取一些值。從外鍵表中檢索字段
隊表:
ID | Name | No_Players | Country | F_Year | Team_Logo
-----+---------------+------------+----------+--------+----------------------
1 | Real Madrid | 22 | Spain | 1940 | Http://Xyz.jpg
2 | Arsenal | 22 | England | 1950 | Http://XXYYZZ.jpg
3 | FCB.Barcelona | 22 | Spain | 1960 | Http://YYZZz.jpg
4 | Bayern Meunekh| 22 | Germany | 1940 | Http://GGG.jpg
匹配表:
ID | Date |First_Team | Second_Team | M_Country |M_City | M_Period | Result
------------------------------------------------------------------------------------------
1 |15-02-2016 | Real Madrid | Arsenal | Spain | Madrid | 120 | 1-1
2 |19-03-2016 | FCB.Barecolna | Madrid | Spain | Madrid | 90 | 4-5
而且我想要得到的Team_Logo對於每個隊在比賽表中JSON形式在這個PHP腳本。我試圖獲得團隊徽標,但不幸的是,查詢無效。
如果有人能幫助我嗎?
<?php
require ('config.php');
$conn = mysqli_connect($servername, $username, $password, $db);
$query = "select * from matches,team where matches.first_team=team.Name OR matches.second_team=team.Name";
$result = mysqli_query($conn, $query);
$rows = array();
echo mysqli_error($conn);
while($row = mysqli_fetch_assoc($result)) {
$rows[]=$row;
}
echo json_encode($rows);
?>
您需要使用連接 – Nehal