I want to calculate the sum of each row in mysql and display in php.
for eg
amount1 | amount2 | total 100 | 200 |
300 | 200 |
How to display the total of each column? Here is the code. My code displays the whole table total and displays. What is the wrong with the code.
$query="SELECT *, sum(amount1+amount2) as total FROM contribution";
$run = mysql_query($query);
while($row=mysql_fetch_assoc($run))
{ ?>
<tr><td><?php echo $row['uid'] ?></td><td><?php echo $row['name'] ?></td><td><?php echo $row['Date'] ?></td>
<td><?php echo $row['month1'] ?></td><td><?php echo $row['amount1'] ?></td>
<td><?php echo $row['month2'] ?></td><td><?php echo $row['amount2'] ?></td><td><?php echo $row['total'] ?></td>
</tr>
<?php } } ?>
Aucun commentaire:
Enregistrer un commentaire