我在我的 Linux 环境(我没有在 Windows 上运行)上尝试了相同的脚本,并且它运行完美。脚本的重点(尽管无关紧要)是打印出表格的内容。
脚本如下:
table_contents.php
<?
$user="root";
$password="";
$database="newtest";
$con = mysqli_connect(localhost,$user,$password,$database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query="SELECT * FROM contacts";
$result = mysqli_query($con,$query);
$num = mysqli_num_rows($result); // COUNT for FOR LOOP
echo '<table border=\'1\'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>'; //This is where it starts printing out everything.
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "</tr>";
}
mysqli_close($con);
?>
table_contents.php 在我的浏览器上显示以下行:
Firstname Lastname '; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['first'] . ""; echo "" . $row['last'] . ""; echo ""; } mysqli_close($con); ?>
表明上面脚本中的注释行是抛出所有要显示的内容之后的点。
为什么会出现这种情况,我该如何解决?