Calculer la sommes des lignes dans un tableau array
RésoluBonjour,
J'ai le tableau suivant sur mon travail php:
<?php
$donnee=mysql_query("SELECT *
FROM bons
ORDER BY num_bon ASC;");
?>
<table>
<thead>
<tr>
<th>Num bon</th> <th>Montant bon</th>
</tr>
</thead>
<tbody>
<?php
while($data=mysql_fetch_array($donnee) )
{
echo'<tr>';
echo'<td>'.$data['num_bon'].'</td> <td>'.$data['montant_bon'].'</td>';
echo'</tr>';
}
?>
</tbody>
<tr>
<td>Somme</td> <td>La somme des montant bon</td>
</tr>
</table>
Je ne sais pas comment faire pour mettre dans la dernière colonne de la dernière ligne la somme des montants des bons
<td> la somme des montant bons </td>
2 réponses
-
Modérateur
Bonjour
$total = 0; while($data=mysql_fetch_array($donnee) ) { $total += $data['montant_bon']; echo'<tr>'; echo'<td>'.$data['num_bon'].'</td> <td>'.$data['montant_bon'].'</td>'; echo'</tr>'; } ?> </tbody> <tr> <td>Somme</td> <td><?php echo $total; ?></td> </
-
Merci bien mon ami jordane45.
Problème résolu.