I have a problem about make total in PHP.
I'd like to make total in my Web App (PHP based) but I get subtotal from database MySQL. And I will print it into table.
Here it is my code :
<table class="ui single selectable table">
<tbody>
<?php
$idTrx = $_POST['idTrx'];
$idUser = substr($idTrx, 3);
$total;
$query = "select trx.id_trx, tempTrx.id_user, tempTrx.nameProduct as nameProduct, tempTrx.price as price, tempTrx.qty as qty, tempTrx.subtotal as subtotal from trx,tempTrx where (trx.id_trx='" . $idTrx . "' and trx.status='1') and tempTrx.id_user='" . $idUser . "';";
$result = mysqli_query($link, $query);
while ( $data = $result->fetch_array(MYSQLI_ASSOC) ) {
echo "<tr><td>x</td><td>".$data['nameProduct']."</td><td>".$data['price']."</td><td>"
.$data['qty']."</td><td>".$data['subtotal']."</td></tr>";
for ($i=0; $i < count($data) ; $i++) {
$total += $data['subtotal'];
}
}
?>
</tbody>
<tfoot>
<tr>
<th>
Total
</th>
<th></th>
<th></th>
<th></th>
<th><?php echo $total ?></th>
</tr>
</tfoot>
</table>
I don't know how to make total from $data['subtotal']
with specific amount of $data
.
After I added $total += $data['subtotal'];
, I still don't get correct $total
from it.