将sql表导入html时获得0结果

时间:2017-04-24 17:40:52

标签: php html mysqli html-table

我刚开始使用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>

希望有人可以帮助我:)

1 个答案:

答案 0 :(得分:1)

您错过了查询中的SELECT:

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