我有一个通过mysql链接的表。我有 5 列显示:名称、商店、描述、欠款和成本。我写了一个脚本来计算“欠款”和“成本”的总数。我无法从总“欠款”中减去总“成本”。
下面是我的代码。
<div>
<table id="datatables" class="display">
<thead>
<tr>
<th>Name</th>
<th>Shop</th>
<th>Description</th>
<th>Amount due</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?=$row['name']?></td>
<td><?=$row['category']?></td>
<td><?=$row['subject']?></td>
<td><?=$row['custom1']?></td>
<td><?=$row['custom2']?></td>
</tr>
<?php
}
?>
<?php
$query = "SELECT custom1, SUM(custom1) FROM hesk_tickets";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "Total Owed". $row['custom1']. " = £". $row['SUM(custom1)'];
echo "<br />";
}
?>
<?php
$query = "SELECT custom2, SUM(custom2) FROM hesk_tickets";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "Cost exVAT". $row['custom2']. " = £". $row['SUM(custom2)'];
echo "<br />";
echo "Profit". $row['custom1 , custom2']. " = £". $row['SUM(custom1 - custom2)'];
echo "<br />";
}
?>
</tbody>
</table>
</div>
任何帮助将不胜感激