I'm wanting to calculate values from a table. Each column has different values, at the end of the table, I would like to enter the total value. Below is my html.
<table class="table table-striped m-table m-table--head-bg-success">
<thead>
<tr>
<th>Nº doc</th>
<th>Valor doc</th>
<th>Correção doc</th>
<th>Multa doc</th>
<th>Valor extra doc</th>
<th>Valor Total</th>
</tr>
</thead>
<tbody>
<?php
$sql = $db->prepare("SELECT * FROM doc where cod_doc = '$id_get' ORDER BY data ASC ");
$sql->execute(); $a = 0 ;
while($row=$sql->fetch(PDO:: FETCH_ASSOC)){
$a++;
$pct_multa = 2;
$pct_ext = 1;
$pct_cob = 10;
$valor_doc = $row['valor_doc'];
$data = $row['data'];
?>
<tr>
<th scope="row">
<? echo $row['numero_doc']?>
</th>
<td id="sum1">
<? echo str_replace('.', ',', $valor_doc)?>
</td>
<td id="sum2">
<? echo str_replace('.', ',', $doc_correcao)?>
</td>
<td id="sum3">
<? echo valorMulta($valor_doc,$pct_multa) ?>
</td>
<td id="sum4">
<? echo valorext($valor_doc,$pct_ext) ?>
</td>
<td id="sum5"><span class="m-widget6__text m--align-right m--font-boldest m--font-brand">
<? echo valorTotal($valor_doc,$pct_ext,$pct_multa, $data) ?>
</span></td>
</tr>
<?php } ?>
</tbody>
</table>
I've created an id for every td (Ex: id="sum1") of the total column I want to calculate. How can I proceed? Thank you in advance for your attention.