我已经从位置连接了FirstPositionID / SecondPositionID和PositionID(PRIMARY KEY)。每个positionID都有一个位置名称。由于我有2个位置,由位置ID设置的玩家,不应该php打印我设置的每个id的位置名称? 当我打印PositionName时,它会打印我在position表中插入的所有位置。 这是我的桌子
Player:Agrabanis Overall:64 Position: Point Guard
Player:Athineou Overall:64 Position: Point Guard
Player:Agrabanis Overall:64 Position: Shooting Guard
Player:Athineou Overall:64 Position: Shooting Guard
Player:Agrabanis Overall:64 Position: Small Forward
Player:Athineou Overall:64 Position: Small Forward
Player:Agrabanis Overall:64 Position: Power Forward
Player:Athineou Overall:64 Position: Power Forward
Player:Agrabanis Overall:64 Position: Center
Player:Athineou Overall:64 Position: Center
结果:
{{1}}
由于我设置了第一个玩家位置ID 5,4和第二个玩家位置ID 2,1不应该只为第一个玩家打印中心,大前锋(4,5位置ID)和第二个玩家射击后卫,控卫(2 ,1位ids)
答案 0 :(得分:0)
请使用left join
或inner join
而不是交叉联接,并将您的SQL字符串更改为
SELECT pl.PlayerName, pl.FirstPositionID, pl.Overall,
pl.SecondPositionID, po1.PositionName AS FirstPositionName,
po2.PositionName AS SecondPositionName FROM players pl
LEFT JOIN positions po1 ON(pl.FirstPositionID = po1.PositionID )
LEFT JOIN positions po2 ON (pl.SecondPositionID = po2.PositionID )
LIMIT 0,100
另外,在循环到
时改变你while($row = mysqli_fetch_assoc($reg)){
echo "</br>Player:".$row['PlayerName']." Overall:".$row['Overall']." Position1: ".$row['FirstPositionName']." Position2:".$row['SecondPositionName '];
}
我认为这会对你有帮助......