最后一部分需要帮助。我怎样才能把费用总和从收入中减去来得到剩下的……
收入-费用=剩余...你明白了..
猜猜我的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>";