有不同的事情似乎不是正确的方法,甚至在您的代码中是不正确的。试试这个,如果你有问题,不要犹豫,我会尽量更新。
_通常从查询结果中提取行的最佳方法是使用专门为此而创建的函数,例如
mysqli_fetch_assoc
(它将使用别名或列名作为数组的键)
_
implode
在理论上是无用的
$result['Diff']
是一个int(实际上您需要一个int),甚至会抛出一个错误
_现在还不清楚你想要的是之前和现在的差别是10,还是10%的电流。示例显示了第一个
<?php
$Difference_Query = "SELECT (SUM(current) * 100) / ((SUM(cw_1) + SUM(cw_2)) / 2) AS Diff FROM table GROUP BY time";
$Difference = mysqli_query($connect, $Difference_Query);
$previous = 0;
while($result = mysqli_fetch_assoc($Difference)) {
//abs is in case results are not in ascending order; this if will test if current is more than previous+10 or less than previous-10
if(abs($result['Diff'] - $previous) > 10) {
echo "<font color = 'red'>".number_format($result['Diff'], 2, ",", ".")."%"."</font>"."<br>";
} else {
echo number_format($result['Diff'], 2, ",", "."), "%", "<br>";
}
$previous = $result['Diff'];
}
?>