我已经仔细检查了,一切看起来都很封闭,所以我无法找到错误。我只想创建一个表来显示mySQL数据。
编辑:我不知道为什么结尾标记高于代码的其余部分,但是当它在正确的位置时仍然会出现错误。<?php
$servername = "localhost";
$username = “x”;
$password = “x”;
$dbname = “x”;
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM Classroom”;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo “<tr><th>Building</th><th>Floor</th><th>Room</th><th>Instructional</th><th>Type<th>Size</th>
<th>Seating</th><th>Decking</th><th>Access</th><th>Whiteboard</th><th>Chalkboard</th></tr>”;
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo “<tr><td>”.$row[“building”].”</td></tr>”;
}
} else {
echo (“0 results”);
}
mysqli_close($conn);
}
?>
答案 0 :(得分:3)
修改:根据原始帖子https://stackoverflow.com/revisions/27974352/1
这应该放在最底层:
?>
事实上,除非你要在它之后添加一些纯HTML,否则它甚至不需要。因此,将其彻底排除可能会让您在将来免于头痛。
但是,你的几个双引号看起来很时髦。您可能会检查它们只是双引号,而不是特殊字符。
在整个代码中,应使用常规双引号“ ”
替换这些引用/智能引号"
。
}
,即mysqli_close($conn);
之后的{{1}}。大括号的数量不匹配。答案 1 :(得分:0)
这有效!
<?php
mb_internal_encoding('UTF-8');
$servername = "localhost";
$username = "x";
$password = "x";
$dbname = "x";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM Classroom";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo "<tr><th>Building</th><th>Floor</th><th>Room</th><th>Instructional</th><th>Type<th>Size</th>
<th>Seating</th><th>Decking</th><th>Access</th><th>Whiteboard</th><th>Chalkboard</th></tr>";
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row["building"]."</td></tr>";
}
}else{
echo("0 results");
}
mysqli_close($conn);
?>
答案 2 :(得分:-1)
从所有文档中删除?>
,因为它不需要,因为PHP自我在文件末尾关闭。