【问题标题】:Getting 0 results while importing sql table to html [duplicate]将sql表导入html时得到0个结果[重复]
【发布时间】:2017-04-25 17:25:09
【问题描述】:

我刚开始使用 mysql 和 php。

我正在尝试在表中显示 mysql 数据库。看起来代码正在运行,但它给出了 0 个结果。我在 mysql 表中有 2 行。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Tronios Exportzendingen</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="styles2.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <?php
        $servername = "localhost";
        $username = "rubinjo13";
        $dbname = "project1";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
             die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "ExportID, Debiteur, Deb_Name, Tot_Pallets, Tot_Weight, PBS FROM export";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
             echo "<table><tr><th>ID</th><th>Debiteur</th><th>Naam</th><th>Aantal Pallets</th><th>Totaal Gewicht</th><th>PB Nummers</th></tr>";
             // output data of each row
             while($row = $result->fetch_assoc()) {
                 echo "<tr><td>" . $row["ExportID"]. "</td><td>" . $row["Debiteur"]. " " . $row["Deb_Name"]. "</td></tr>"
                 . $row["Tot_Pallets"]. "</td><td>" . $row["Tot_Weight"]. "</td><td>" . $row["PBS"]. "</td><td>"; 
             }
             echo "</table>";
        } else {
             echo "0 results";
        }

        $conn->close();
        ?>  
</body>
</html>

希望有人能帮帮我:)

【问题讨论】:

  • $sql = "ExportID, Debiteur, Deb_Name, Tot_Pallets, Tot_Weight, PBS FROM export"; ??你怎么错过了选择??

标签: php html mysqli html-table


【解决方案1】:

您错过了查询中的 SELECT:

$sql = "SELECT ExportID, Debiteur, Deb_Name, Tot_Pallets, Tot_Weight, PBS FROM export";

【讨论】:

    猜你喜欢
    • 2020-06-07
    • 2017-02-17
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    相关资源
    最近更新 更多