I try to design a web that keep track the match history of students.
tablegame has 4 column: player 1, player2 ,player 3 and player4. All of them are represented as ids in tablegame.(each game has a maximum of 4 player)
The column player1 player2 always store the IDs who win this game, and column player 3 player4 always store IDs who lose this game.
Tableplayer store basic information about the student.
However, as I fetch associated array from the $AimStudentHistoryWin. Data get repeatly fetched.
THE web actually shows me this:
================
GAMEID 15
================
GAMEID 16
================
GAMEID 15
================
GAMEID 16
================
GAMEID: 15
================
GAMEID 16
BUT I expect the web to only show me
================ GAMEID 15
================ GAMEID 16
How could I Fix that?
echo "<br><br> <center><h2>match history:</h2> <br>";
$Aimstudenthistorywin=$conn ->query( "SELECT tablegame.*,tableplayer.Name FROM tablegame INNER JOIN tableplayer ON tablegame.player1 ='$studentid' OR tablegame.player2 ='$studentid'");
$Aimstudenthistoryloss=$conn ->query("SELECT tablegame.*,tableplayer.Name FROM tablegame INNER JOIN tableplayer ON tablegame.player3 ='$studentid'OR tablegame.player4 ='$studentid'" );
$Num=0;
While($row2= $Aimstudenthistorywin ->fetch_assoc()){
echo "<br>================<br><i style ='color:blue;'><h3>WIN</h3></i>";
echo "<br>Game".$Num;
$Num++;
echo "<br>".$row2['GameID'].":<br>".$row2['Name'];
}while($row2 = $Aimstudenthistoryloss -> fetch_assoc()){
echo "<br>================<br><i style ='color:red;'><h3>Lose</h3></i>";
echo "<br>Game".$Num;
$Num++;
echo "<h3>StudentName:".$TempStudentArray[$row2['player1']]."</h3><br>Game Date:".$row2['Date']."<br><br>"."----------------<br>Player1:".$TempStudentArray[$row2['player1']]."|||||||"."Player2:".$TempStudentArray[$row2['player2']]."<br><br>vs<br><br>Player3:".$TempStudentArray[$row2['player3']]."|||||||| Player4".$TempStudentArray[$row2['player4']]."<br>-------" ;
}
echo"</center>"