I confess that I am a beginner. My goal is to be able to summarize in a two-dimensional table the amount per month (in column) for each class (in line). After doing a lot of research, I arrived at this stage in my project.

My problem is , I get the result with months repeating in columns like here.

[![My result](https://i.stack.imgur.com/hYLlr.png)](https://i.stack.imgur.com/hYLlr.png)

Here is my code.
This is my sql code : 
```
"SELECT classe, mois, sum_ec FROM journal"
```

This is my php code :

```
<?php

$tableau = array();
$tblClasse = array();
$rt = mysqli_query($db, $req_sit);//execute la requete
while ($row = $rt->fetch_assoc()){ //forme le tableau
    $tableau[$row['classe']][$row['mois']] = $row['sum_ec'];

    if (!in_array($row['classe'],$tblClasse)) { 
        $tblClasse[] = $row['mois']; 
    }
}

echo '<table border="1">
        <tr>
            <th>&nbsp;</th>';

foreach ($tblClasse as $classe) {
    echo '<th>' . htmlspecialchars($classe) . '</th>';
}
echo '</tr>';

foreach ($tableau as $mois=>$value) {
    echo '<tr>';
    $new_line = TRUE;
    foreach ($tblClasse as $classe) {
        if ($new_line) {
            echo '<td>' . $mois . '</td>';
            $new_line = FALSE;
        }

        $display = isset($value[$classe]) ?   $value[$classe] : "&nbsp;";
        echo '<td>' . $display . '</td>';
    }
    echo '</tr>';
}
?>

```

Can someone tell me what mistake I made?