how to subtract from this "not-best-practice-table"
<p>Need help with the last part. how can I take the expense sum and subtract that from the income to get what leftover....</p>

<p>Income - Expense = leftover... you get the point..</p>

<p>Guess my mysql tables are not the best way to do it, but im a rookie and this is what I came up with...</p>

<pre><code>// summary income

$query_income = "SELECT type, SUM(january), SUM(february), SUM(march), SUM(april),     SUM(may), SUM(june), SUM(juli), SUM(august), SUM(september), SUM(october), SUM(november), SUM(december) FROM data WHERE year = '2012' AND type = '1'";
$results = mysql_query($query_income);

while($row = mysql_fetch_array( $results )) {

   $total_income = $row['SUM(january)'] + $row['SUM(february)'] + $row['SUM(march)'] + $row['SUM(april)'] + $row['SUM(may)'] + $row['SUM(june)'] + $row['SUM(juli)'] + $row['SUM(august)'] + $row['SUM(september)'] + $row['SUM(october)'] + $row['SUM(november)'] + $row['SUM(december)'];

 echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;b&gt;Income&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(january)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(february)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(march)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(april)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(may)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(june)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(juli)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(august)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(september)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(october)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(november)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row['SUM(december)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($total_income) ."&lt;/td&gt;";
 echo "&lt;/tr&gt;";

}

// summary expenses

$query_expense = "SELECT type, SUM(january), SUM(february), SUM(march), SUM(april), SUM(may), SUM(june), SUM(juli), SUM(august), SUM(september), SUM(october), SUM(november), SUM(december) FROM data WHERE year = '2012' AND type = '2'";
  $results = mysql_query($query_expense);

while($row1 = mysql_fetch_array( $results )) {

   $total_expense = $row1['SUM(january)'] + $row1['SUM(february)'] + $row1['SUM(march)'] + $row1['SUM(april)'] + $row1['SUM(may)'] + $row1['SUM(june)'] + $row1['SUM(juli)'] + $row1['SUM(august)'] + $row1['SUM(september)'] + $row1['SUM(october)'] + $row1['SUM(november)'] + $row1['SUM(december)'];


   echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;b&gt;Expenses&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(january)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(february)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(march)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(april)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(may)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(june)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(juli)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(august)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(september)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(october)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(november)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($row1['SUM(december)']) ."&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;" . number_format($total_expense) ."&lt;/td&gt;";
 echo "&lt;/tr&gt;";

}

// summary, whats left

   echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;b&gt;Leftover&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
  echo "&lt;td style='text-align:right'&gt;&lt;/td&gt;";
 echo "&lt;/tr&gt;";
</code></pre>
