-2

我正在尝试将多行中的货币加在一起。以下是我到目前为止的代码。我不确定 SUM 应该在哪里。

如果可能的话,我还想使用 FPDF 以 PDF 格式输出结果表。我尝试粘贴我的代码,但无法让它工作,一直给我错误,它的格式不正确。我一直按CTRL+k并输入代码,但它不起作用;

有什么建议吗?

<?php
session_start(); // start up your PHP session! 
?>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Accounting Page</title>
    <link rel="stylesheet" type="text/css" href="../css/table.css"/>
    <script src="../js/table.js" type="text/javascript"></script>
</head>
<?php
error_reporting(0);
$con = mysql_connect("localhost", "root", "rq5f4mkn");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("charitabledb", $con);
$sql = "SELECT * FROM accounting";

$result = mysql_query($sql);
?>
<div id="content">
    <div id="blog">
        <div id="articles" style="width:692px;padding:0;">
            <table width="250" border="1" class="example table-autosort table-autofilter   
         table-autopage:10 table-stripeclass:alternate table-page-number:t1page table-
         page-count:t1pages table-filtered-rowcount:t1filtercount table-
         rowcount:t1allcount" id="t1">
                <thead>
                <tr style="height:35px">
                    <th class="table-filterable table-sortable:default table-sortable" title="Click 
          to sort">Date
                    </th>
                    <th class="table-filterable table-sortable:default table-sortable"
                        title="Click to sort">Transaction Type
                    </th>
                    <th class="table-filterable table-sortable:default table-sortable"
                        title="Click to sort">Account
                    </th>
                    <th class="table-filterable table-sortable:default table-sortable"
                        title="Click to sort">Description
                    </th>
                    <th class="table-filterable table-sortable:default table-sortable"
                        title="Click to sort">Amount
                    </th>
                </tr>
                </thead>
                <tbody>
                <?php
                while($row = mysql_fetch_array($result))
                {
                ?>
                <tr>
                    <td><?php echo $row['date']?></td>
                    <td><?php echo $row['transactiontype']?></td>
                    <td><?php echo $row['account']?></td>
                    <td><?php echo $row['description']?></td>
                    <td><?php echo $row['amount']?></td>

                    <?php
                    }
                    mysql_close($con);
                    ?>
                </tbody>
                <tfoot>

                <tr>
                    <td style="cursor:pointer;"
                        class="table- page:previous">&lt; &lt;Previous
                    </td>

                    <td style="text-align:center;" colspan="1">Page <span id="t1page">1</span>&nbsp;of
                        <span id="t1pages">11</span></td>
                    <td style="cursor:pointer;" class="table-page:next">Next &gt; &gt;</td>
                </tr>
                <tr>
                    <td colspan="3"><span id="t1filtercount">105</span>&nbsp;of
                        <span id="t1allcount">105</span>&nbsp;rows match filter(s)
                    </td>
                </tr>
                </tfoot>
            </table>
4

1 回答 1

0

如果您只是汇总表中的所有值:

mysql_query("SELECT SUM(amount) FROM accounting");
于 2013-03-18T20:04:28.160 回答