【发布时间】:2015-03-07 13:47:34
【问题描述】:
我试图在我的 html 页面中显示一个数据库表,但似乎无法让它工作。 (代码如下):
<!DOCTYPE html>
<html>
<body>
<h1> Table </h1>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Library";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `books` ORDER BY `Category` ASC ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["ISBN"]. " Name: ". $row["firstname"]. " - Author: " . $row["BookAuthor"]. " Category: " . $row["Category"]. " - Quantity: " . $row["Quantity"]. " - Price: " . $row["Price"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>
我使用 WAMP 服务器,“books”表位于名为 Library 的数据库中。但是表格没有显示,我得到的只是显示的 php 代码。
你知道出了什么问题吗?
谢谢!
【问题讨论】:
-
是.php后缀的文件吗?