如何從收到的總金額中扣除總費用並將其顯示在總收入中?如何從不同的表中添加2個總數?
的數據來自不同的表從我的數據庫..可惜我不能上傳更清晰的視圖PIC ..
TOTAL AMOUNT RECEIVED || 15610
TOTAL EXPENSES || 11300
TOTAL REVENUES || (this must be equal to TOTAL AMOUNT RECEIVED - TOTAL EXPENSES)
這裏是我的代碼:
<table width="383" border="1" bordercolor="#00CCFF">
<tr>
<td width="245" bgcolor="#0099FF">TOTAL AMOUNT RECIEVED</td>
<td width="128" bgcolor="#FFFFFF">
<?php
include("confstudents.php");
$id = $_GET['id'];
$query = "SELECT id, SUM(1stPayment + 2ndPayment + 3rdPayment + 4thPayment) um_payment FROM student_payments";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "" . $row['sum_payment'];
echo "<br/>";
}
?>
</td>
</tr>
<tr>
<td bgcolor="#0099FF">TOTAL EXPENSES</td>
<td bgcolor="#FFFFFF">
<?php
include("confexpenses.php");
$id = $_GET['id'];
$query = 'SELECT SUM(piece * price) tprice FROM expenses';
$result = mysql_query($query) or die(mysql_error());
while($res = mysql_fetch_assoc($result)){
echo " " . $res['tprice']; " ";
}
?>
</td>
</tr>
<tr>
<td bgcolor="#0099FF">TOTAL REVENUES</td>
<td bgcolor="#FFFFFF">
<?php
include("totalrev.php");
?>
</td>
</tr>
</table>
在第一循環中,添加'$行[ 'sum_payment']''到$ total_received'。在第二個循環中添加'$ res ['tprice']'到'$ total_expenses'。最後,計算'$ total_revenues = $ total_received - $ total_expenses'。 – Barmar