I use a mysql query to get the following data from games played between two teams:
| name |score|
---------------
|John | 7 |
|Danny | 0 |
|John | 7 |
|Peter | 5 |
Then I use some PHP code (see below) to display the data as follows:
|Player 1|Score 1|Player 2|Score 2|
-----------------------------------
|John | 7 |Danny | 0 |
|John | 7 |Peter | 5 |
But I want:
|Player 1| Score |Player 2|
-----------------------------
|John | 7 - 0 |Danny |
|John | 7 - 5 |Peter |
The code I am using to display two rows from sql side-by-side with PHP (inspired from here) is:
// output data of each row
$i = 0;
while($row = $result->fetch_assoc()){
// Odd row opens
if (++$i % 2 != 0) echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['score']."</td>";
// Even row closes
if ($i % 2 == 0) echo "</tr>";
}
I am struggling for many days now but can't seem to find a way to get it right. If it might help I could provide the actual sql query and my complete Table structure as an image.
Any help greatly appreciated. Thanks!