title: calculate the sum of each column in sql and php
body: <p>I want to calculate the sum of each row in mysql and display in php.</p>
  
  <p>for eg</p>
  
  <blockquote>
    <p>amount1 | amount2 |  total   100     |   200   |          </p>
    
    <p>300     |   200   |</p>
  </blockquote>
  
  <p>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.</p>
  
  <pre><code>$query="SELECT *, sum(amount1+amount2) as total FROM contribution";
   $run = mysql_query($query);
  
  while($row=mysql_fetch_assoc($run))
  { ?&gt;
  &lt;tr&gt;&lt;td&gt;&lt;?php echo $row['uid'] ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $row['name'] ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $row['Date'] ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row['month1'] ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $row['amount1'] ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row['month2'] ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $row['amount2'] ?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $row['total'] ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php } } ?&gt;
  </code></pre>