我有一张名为玩家的桌子
p_id | first | last
========================
1 | Michael | Jordan
2 | Charles | Barkley
3 | Kobe | Bryant
4 | Allen | Iverson
5 | Kevin | Garnett
然后我有一个名为users的表
u_id | user | player_1 | player_2 | player_3
============================================
1 | John | 1 | 2 | 5
2 | Jane | 3 | 4 | 5
3 | Jim | 2 | 3 | 4
通过网站上的表格,用户选择他们的球员(字段:player_1,player_2,player_3对应于players表中的id
我正在尝试运行 INNER JOIN,在其中打印用户表中的用户及其玩家选择(第一个,最后一个)
到目前为止我有这个
SELECT * FROM users
INNER JOIN players p1 ON player_1 = p1.player_id
INNER JOIN players p2 ON player_2 = p2.player_id
INNER JOIN players p3 ON player_3 = p3.player_id
INNER JOIN players p4 ON player_4 = p4.player_id
INNER JOIN players p5 ON player_5 = p5.player_id
ORDER BY data";
当我跑
while ($row = mysql_fetch_assoc($result_users))
{
$player_1_first = $row['player_name'];
$player_1_last = $row['player_last'];
echo $player_1_first." ".$player_2_last;
}
我只得到用户的最后一个选择。
我的问题: 我如何才能正确地完成我想要实现的目标?