<?php
$con=mysqli_connect("localhost","root","root","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$results = mysqli_query($con,"SELECT SUM(jumlah) AS jumlah_sum FROM finance_income");
echo '<center>';
/*while($rows = mysqli_fetch_array($results));
{ *?
echo "<p>" . "Rp " . number_format($rows['jumlah_sum']) . "</p>";
/*}*/
echo "</center>";
mysqli_close($con);
?>
那是我的代码,我认为它正在工作,但是当我在我的 mamp 中打开它时,它只打印了 0 而不是 2,800,000,2,800,000 是列“jumlah”的总和
id timestamp_ _ __ _ __ _ nama cat_id jumlah
1 2013-10-26 14:08:18 测试 Iuran 400000
2 2013-10-26 22:06:35 测试多纳西 2000000
3 2013-10-27 10:51:32 测试 Iuran 100000
4 2013-10-27 10:55:01 测试 Iuran 100000
5 2013-10-27 11:01:38 测试 Iuran 100000
6 2013-10-27 11:02:07 测试 Iuran 100000
编辑:我尝试删除 while 并且它有效,谢谢