我有一个非常愚蠢的问题。我正在从 mysql 中提取收入和支出的总额,然后我想从收入中减去支出。由于某种原因,结果不是剩下的,而是显示了收入数字 - 支出数字。
代码如下
function total_by_type_between_dates($type, $start, $end){
global $uc_con;
$start = strtotime ($start);
$end = strtotime ($end);
$sql = "SELECT SUM(amount) AS total FROM account WHERE `time` > $start && `time` < $end && `type` = '$type'";
$result = $uc_con->query($sql);
$row = $result->fetch_array(MYSQLI_ASSOC);
$total = number_format((float)$row['total'], 2, '.', '');
echo $total;
}
function total_expense_between_dates($start, $end){
global $uc_con;
$start = strtotime ($start);
$end = strtotime ($end);
$sql = "SELECT SUM(amount) AS total FROM account WHERE `time` > $start && `time` < $end && `type` != 'income' && `type` != 'mileage'";
$result = $uc_con->query($sql);
$row = $result->fetch_array(MYSQLI_ASSOC);
$total = number_format((float)$row['total'], 2, '.', '');
return $total;
}
echo total_by_type_between_dates('income', $date_begining, $date_ending)-total_expense_between_dates($date_begining, $date_ending);
奇怪的是结果显示如下:2770.69-407.42而不是2363.29
谁能告诉我可能是什么原因造成的
皈依舞
狐的传说
随时随地看视频慕课网APP