我有三張表,我希望能夠有一個HTML選擇選項來顯示玩家的名字以及他們能夠玩的主要和次要位置。玩家表只將它們存儲爲整數,而不是它們被稱爲。我創建了一個查找表,將數字轉換爲實際位置,例如「C」=「1」。當我運行下面的SQL查詢時,它不會在我的數組中顯示任何內容。加入三張表和PHP的SQL代碼
Player
Player_ID PrimaryPosition SecondaryPosition PlayerName
1 2 1 Bob
2 1 3 Billy
Team
Player_ID TeamID TeamName
1 1 Hobos
2 1 Rejects
PosLookup
PosNbr PosLabel PosLabel2
1 C C
2 P P
3 1B 1B
SELECT Player.PlayerName, PosLookup.PosLabel, PosLookup.PosLabel2, Player.Player_ID FROM Team, Player, PosLookup WHERE Player.Player_ID = Team.Player_ID and Team.TeamID = '1' and PosLookup.PosNbr = Player.PrimaryPosition and PosLookup.PosNbr = Player.SecondaryPosition ORDER BY PosLabel ASC
foreach($rowarray as $row)
{
echo "<option value = $row[PlayerID] >$row[PlayerName] $row[PosLabel] $row[PosLabel2]</option>";
$cntr++;
}
Desired OUTPUT Dropdown
Bob P C
Billy C 1B
不行,它仍然只顯示他們玩的一個位置 – punkdis 2012-01-13 06:08:06
啊哈,可能是因爲兩者都返回c olumns被稱爲'PosLabel',所以'$ row ['PosLabel']'被覆蓋。更新答案。 – 2012-01-13 06:32:57
就是這樣。謝謝 – punkdis 2012-01-13 13:26:03