-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>';

 while($rows = mysqli_fetch_array($results)); 
 {
     echo "<p>" . "Rp " . number_format($rows['jumlah_sum']) . "</p>";
 }
 echo "</center>";

 mysqli_close($con);



?>

我已经更改了一些代码,但是当我打开这个 php 文件时,它并没有添加我所有的号码,它只是在网络上打印 0 有人知道会发生什么吗?

Full texts  
id
timestamp
nama
cat_id
jumlah

1
2013-10-26 14:08:18
test
Iuran
400000

2
2013-10-26 22:06:35
test
Donasi
2000000

3
2013-10-27 10:51:32
test
Iuran
100000

4
2013-10-27 10:55:01
test
Iuran
100000

5
2013-10-27 11:01:38
test
Iuran
100000

6
2013-10-27 11:02:07
test
Iuran
100000

那是我的数据库谢谢你,瑞恩

4

1 回答 1

1

msqli_connect用于连接但mysql_query用于查询。不要混合两个库。使用mysqli_query而不是mysql_query. 对于mysql_fetch_array. 利用mysqli_fetch_array

 <?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);
于 2013-10-27T05:14:58.193 回答