Question: How do I made the column, teamname, as a header for my rows. For example, I would like to output this result using PHP:

\*\*\*\*\*\*\*\*\* Sandstorm 2:\*\*

```
summonername2
summoner 1
summoner 2
summoner 3
summoner 4

```

**Team #5**

```
Summoner 1
Summoner 1

```

Here is the code that I have in PHP. So far, its outputting unexpected results.

```
$query = "SELECT players.id, team.teamname, players.summonername 
        from team
        INNER JOIN players ON players.team = team.id
        WHERE team.tourneyid = {$id}";
        $result = mysqli_query($conn, $query);
        while($row = mysqli_fetch_assoc($result)) {
            if($i == 0) {
                $heading .= "<h3>". $row['teamname'] ."</h3><table class='table'><tr><th>Summonername</th><th>rank</th></tr>";
            }// team header
            $teams .= "{$heading}<tr><td>". $row['summonername'] ."</td><td>rank</td></tr>";
            $i++;
        }

```

Answer: 
As an alternative, you could also use the `team name` as your key for gathering all values inside grouping them.

After you have gathered them, then present them accordingly:

```
$query = "
    SELECT players.id, team.teamname, players.summonername 
        FROM team
        INNER JOIN players ON players.team = team.id
        WHERE team.tourneyid = {$id}
";

$teams = array();
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result)) {
    $team_name = $row['teamname'];
    $summoner_name = $row['summonername'];
    $teams[$team_name][] = $summoner_name; // continually push same team names under a container
}

// then for presentation
foreach($teams as $team_name => $summoners) {
    echo "<h3>{$team_name}</h3><br/>";
    foreach($summoners as $summoner) {
        echo "<p>{$summoner}</p><br/>";
    }
}

```
You're printing the heading for each row. You probably need to keep track of both the current and the last row, see if the team has changed from the last row to the current, and only print the head in that car. P