casimir92 | Je me réponds à moi-même
Code :
- <table
- <tr>
- <th class="">Produits</th>
- <th class="">Personne1</th>
- <th class="">Personne2</th>
- <th class="">Personne3</th>
- <th class="">Personne4</th>
- </tr>
- <?php
- //création de la requéte SQL
- $reqAllF = $conn->prepare('SELECT * FROM tb_f ORDER BY produit ASC');
- $reqAllF->execute();
- $allF = $reqAllF->fetchAll();
- $total = [
- 'personne1' => 0
- 'personne2' => 0
- 'personne3' => 0
- 'personne4' => 0
- ];
- foreach ($allF as $line)
- {
- $total['personne1'] += $line['montant_personne1'];
- $total['personne2'] += $line['montant_personne2'];
- $total['personne3'] += $line['montant_personne3'];
- $total['personne4'] += $line['montant_personne4'];
- echo "<tr>";
- echo "<td class=produit>".$line['produit']."</td>";
- echo "<td class=montant>".number_format($line['montant_personne1'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($line['montant_personne2'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($line['montant_personne3'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($line['montant_personne4'], 2, ',', ' ')." €</td>";
- echo "</tr>";
- }
- echo "<tr>";
- echo "<td></td>";
- echo "<td class=montant>".number_format($total['personne1'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($total['personne2'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($total['personne3'], 2, ',', ' ')." €</td>";
- echo "<td class=montant>".number_format($total['personne4'], 2, ',', ' ')." €</td>";
- echo "</tr>";
- ?>
- </table>
|
On m'a conseillé de gérer le calcul des totaux par PHP plutôt que dans la requête SQL, se qui me convient Message édité par casimir92 le 31-03-2023 à 13:47:04
|