无法在表格中显示我的结果 - PHP

时间:2017-04-17 18:40:19

标签: php html mysql

我正在尝试在页面上显示我的查询结果。但是,每当我运行代码时,虽然查询是正确的,但它不会显示任何内容。 有人可以帮忙吗?非常感谢

<?php
session_start();
require_once("../config1.php");

if(isset($_POST["DailySales"])) {

  $linkid = mysqli_connect(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD, DB_DATABASE) or die("Could not connect:" . connect_error());

  $sql = "SELECT Retdatetime AS date , sum(rentalrate + overduecharge) AS mny
          FROM frs_FilmRental
          WHERE shopid='2'
          Order BY retdatetime DESC ";

  $result = mysqli_query($linkid, $sql);

  if (!$result)) {
printf("Errormessage: %s\n", mysqli_error($linkid));
 }

  echo "<table border  = '1' align='center'>";
  echo "<th> Shop ID 2</th></tr>";

  while ($row = mysqli_fetch_assoc($result)) {

    echo "<h2><center>Shop ID 2 daily sales : </center></h2>";
    echo "<tr><td>";
    echo  $row['mny'];
    echo "</td><td>";
    echo  $row ['date'];
    echo "</td></tr>";

}
}

?>

2 个答案:

答案 0 :(得分:0)

要了解查询错误,您应该在代码中使用mysqli_error()。如果执行的查询没有错误,那么你可以为它运行while循环。

<?php
session_start();
require_once("../config1.php");

if(isset($_POST["DailySales"])) {

  $linkid = mysqli_connect(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD, DB_DATABASE) or die("Could not connect:" . connect_error());

  $sql = "SELECT Retdatetime , sum(rentalrate + overduecharge) AS mny
      FROM frs_FilmRental
      WHERE shopid='2'
      Order BY retdatetime DESC ";

  $result = mysqli_query($linkid, $sql);

  if (!$result)) {
printf("Errormessage: %s\n", mysqli_error($linkid));
  } else {

  echo "<table border  = '1' align='center'>";
  echo "<tr><th> Shop ID 2</th></tr>";
  while ($row = mysqli_fetch_assoc($result)) {

echo "<h2><center>Shop ID 2 daily sales : </center></h2>";
echo "<tr><td>";
echo  $row['mny'];
echo "</td><td>";
echo  $row ['date'];
echo "</td></tr>";


}
echo "</table>";
}
}
?>

在评论中给出的修正也适用

请复制/粘贴mysqli_error()

给出的错误

答案 1 :(得分:0)

替换

echo  $row ['date'];

通过

 echo  $row ['Retdatetime'];