如何从 TOTAL AMOUNT RECEIVED 中减去 TOTAL EXPENSES 并将其显示在 TOTAL REVENUES 中?
数据来自我数据库中的不同表。不幸的是,我无法上传图片以获得更清晰的视图。
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>