-4

I have this query and i am asking if i can print the result in PHP without saving the result in other table.

SELECT SUM(weekly_fees) FROM scout_cabs
4

1 回答 1

4

你首先给它一个别名来输出:

SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`

然后你通过mysql将它解析为任何正常请求。

<?php
$sql    = "SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`";
$run    = mysql_query($sql);
$result = mysql_fetch_assoc($run);
echo 'The sum of the query is: ' . number_format($result['total']);

如果您还没有使用 mysqli_,它可能也值得研究,因为 mysql_ 现在已弃用。

于 2013-10-20T18:44:32.067 回答