Im trying to rank players according to how many battles they won. It's a 2 player game and the winner is the player with a playerscore of 10.
In my players DB I have the following:
playerID | name
1 Lasse
2 Kevin
4 Brian
My playersfight DB:
fightID | playerID | playerScore
1 1 10
1 2 4
2 4 6
2 2 10
etc..
I can not figure out how to loop the different playerIDs through this query. Right now the playerID 2 is used, but this shall change according my player database active ids.
$query = "SELECT name,
(SELECT DISTINCT count(playerScore) FROM playersfight WHERE playerScore='10' and playerID='2') As Wins,
(SELECT DISTINCT count(playerScore) FROM playersfight WHERE playerScore<'10' and playerID='2') As Loses
FROM players WHERE playerID='2'";
$result = $conn->query($query);
The result i'm looking for should be like:
Name | Win | Loses
Lasse 5 1
Brian 3 2
Kevin 2 2
Thank you in advance