最後の部分で助けが必要です。どうすれば支出の合計を取り、それを収入から差し引いて残りを得ることができますか....
収入 - 支出 = 残り物...あなたはポイントを得る..
私のmysqlテーブルはそれを行うための最良の方法ではないと思いますが、私は新人であり、これが私が思いついたものです...
// 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 "<tr>";
echo "<td><b>Income</b></td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(january)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(february)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(march)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(april)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(may)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(june)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(juli)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(august)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(september)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(october)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(november)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row['SUM(december)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($total_income) ."</td>";
echo "</tr>";
}
// 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 "<tr>";
echo "<td><b>Expenses</b></td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(january)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(february)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(march)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(april)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(may)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(june)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(juli)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(august)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(september)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(october)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(november)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($row1['SUM(december)']) ."</td>";
echo "<td style='text-align:right'>" . number_format($total_expense) ."</td>";
echo "</tr>";
}
// summary, whats left
echo "<tr>";
echo "<td><b>Leftover</b></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "<td style='text-align:right'></td>";
echo "</tr>";