Below is my code i am trying to calculate the sum of values in a single column that is: SUM(sum) as total, which i want to print in the of my output table as Total; but that part of the code is not producing the expected output.
<?php
require_once('includes/connect.php');
$result = mysqli_query($con, "SELECT studentid, hw1, hw2, hw3, SUM(hw1+hw2+hw3) as sum, SUM(sum) as total FROM scores GROUP BY studentid");
echo "<table border='1'>
<thead>
<tr>
<th>StudentID</th>
<th>HW1</th>
<th>HW2</th>
<th>HW3</th>
<th>SUM</th>
</tr>
</thead>";
echo "<tfoot>
<tr>
<td>Total:</td>
<td> echo SUM(sum);</td>
</tr>
</tfoot>";
while ($row = mysqli_fetch_array($result))
{
"<tbody>
<tr>";
echo "<td>" . $row['studentid'] . "</td>";
echo "<td>" . $row['hw1'] . "</td>";
echo "<td>" . $row['hw2'] . "</td>";
echo "<td>" . $row['hw3'] . "</td>";
echo "<td>" . $row['sum'] . "</td>";
echo "
</tr>
</tbody>";
}
echo "</table>";
mysqli_close($con);
?>
I shall appreciate suggestions to resolve this. Thanks.