Php 减去两个总数

Php 减去两个总数,php,subtraction,totals,Php,Subtraction,Totals,我有一个通过mysql链接的表。我有5栏显示:名称,商店,描述,欠款和成本。我写了一个脚本来计算“欠款”和“成本”的总数。我很难从总“欠款”中减去总“成本” 下面是我的代码 <div> <table id="datatables" class="display"> <thead> <tr> <th>Name</th>

我有一个通过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>

名称
商店
描述
应付金额
成本
任何帮助都将不胜感激

这就是问题所在:

echo "Profit". $row['custom1 , custom2']. " = £". $row['SUM(custom1 - custom2)'];
需要:

echo "Profit". $row['custom1']. ",".$row['custom2']." = £". $row['custom1'] - $row['custom2'];

并听取@h2oooo-go的建议,查找使用PHP/MySQL的更好、更安全的方法。

。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果选择PDO,
$row['custom1,custom2']
应该是什么?虽然这不是无效的语法,但从查询结果中获取数据的方法是完全错误的。