title: How to calculate the sum of multiple rows of a single column in mysql
body: <p>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. </p>
  
  <pre><code>&lt;?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 "&lt;table border='1'&gt;
  &lt;thead&gt;
  &lt;tr&gt;
      &lt;th&gt;StudentID&lt;/th&gt;
      &lt;th&gt;HW1&lt;/th&gt;
      &lt;th&gt;HW2&lt;/th&gt;
      &lt;th&gt;HW3&lt;/th&gt;
      &lt;th&gt;SUM&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;";
  
  echo "&lt;tfoot&gt;
  &lt;tr&gt;
      &lt;td&gt;Total:&lt;/td&gt;
      &lt;td&gt; echo SUM(sum);&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tfoot&gt;";
  while ($row = mysqli_fetch_array($result))
  {
  "&lt;tbody&gt;
    &lt;tr&gt;";
      echo "&lt;td&gt;" . $row['studentid'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['hw1'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['hw2'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['hw3'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['sum'] . "&lt;/td&gt;";
      echo "
    &lt;/tr&gt;
   &lt;/tbody&gt;"; 
  }
   echo "&lt;/table&gt;";
  
   mysqli_close($con);
   ?&gt;
  </code></pre>
  
  <p>I shall appreciate suggestions to resolve this.
  Thanks.</p>