列的SUM不起作用它只打印0

时间:2013-10-27 06:56:54

标签: php mysql sql sum

<?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是colum“jumlah”的总和

  

id timestamp_ _ __ _ __ _ nama cat_id jumlah

     

1 2013-10-26 14:08:18测试Iuran   400000

     

2 2013-10-26 22:06:35测试Donasi   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

编辑:我尝试删除了,感谢

1 个答案:

答案 0 :(得分:1)

这是有效的代码。

<?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>';
  $rows = mysqli_fetch_array($results);
  echo "<p>" . "Rp " . number_format($rows['jumlah_sum']) . "</p>";
  echo "</center>";
     mysqli_close($con);

    ?>