Ik heb een database met informatie over het WK voetbal. Eén van de tabellen (tournament_standings) bevat informatie over plek 1, 2 en 3 waar een land is geëindigd. Nu wil ik de 3 rijen samenvoegen tot één rij met daarbij het land op de 1e plek, 2e plek en 3e plek.

Mijn huidige pagina ziet er nu zo uit , maar moet er uit gaan zien zoals deze pagina . Hoe is dit te realiseren in PHP

Hieronder mijn code tot nu toe.

<table class="table table-striped table-bordered">
			<thead>
				<tr>
                    <th>World Cup</th>
                    <th>Host</th>
                    <th>Country</th>
                    <th>Position</th>
                    <th>MP</th>
                    <th>GS</th>
                    <th>AVG</th>
				</tr>
			</thead>
			<tbody>

            <?php
                $query = "SELECT    tournament_standings.tournament_id, 
                                    tournament_standings.position, 
                                    tournament_standings.team_id,
                                    tournaments.tournament_id,
                                    tournaments.host_country,
                                    teams.team_id,
                                    teams.team_code,
                                    teams.team_name
                            FROM tournament_standings 
                            INNER JOIN teams 
                            ON tournament_standings.team_id = teams.team_id
                            INNER JOIN tournaments
                            ON tournament_standings.tournament_id = tournaments.tournament_id
                            WHERE tournament_standings.position < '4'
                            ORDER BY tournament_standings.tournament_id ASC";
                
                $query_run = mysqli_query($conn, $query) or die("database error:". mysqli_error($conn));

                
                if(mysqli_num_rows($query_run) > 0)
                {
                    foreach($query_run as $row)
                    {
                        ?>
                        <tr>
                            <td><?= $row['tournament_id']; ?></td>
                            <td><?= $row['host_country']; ?></td>
                            <td><?= "<img src=../images/flags/country/" .$row['team_code'] .".png>" ." " .$row['team_name']; ?></td>
                            <?php if ($row['position'] == 1) { ?> <td>Champion</td> <?php }if ($row['position'] == 2){ ?> <td>Runner up</td> <?php }if ($row['position'] == 3){ ?> <td>Third place</td> <?php }?>
                        </tr>
                        <?php
                    }
                }
                else
                {
                    ?>
                        <tr>
                            <td colspan="4">No Record Found</td>
                        </tr>
                    <?php
                }
            ?>

Reageren