我正在尝试阅读存储在 mysql 表中的评论。出于某种原因,即使最后一行是空白的,我总是在文件的最后一行出现解析错误。我不确定它是否相关,但 connect.php 可用于将评论放入数据库。我正在使用 wampserver 来托管它并手动对其进行编码。
我认为这与 while 循环有关,当我在结尾处注释掉 while(){ 和 } 时,我只会得到一些缺少的变量错误,正如您所期望的那样。我对 php 编码很陌生,所以我很确定问题很简单,我要么错过了,要么没有正确理解。
无论如何,这是我的代码:
<?php
include "connect.php";
?>
<?php
$sql = "SELECT * FROM main";
$result = mysql_query($sql) or die("Could not get posts from table");
while($rows=mysql_fetch_array($result)){
?>
<table bgcolor="green" align="center">
<tr>
<td></td>
</tr>
<tr>
<td><strong> <? echo $rows['name']; ?> </strong></td>
</tr>
<tr>
<td> <? echo $rows['email']; ?> </td>
</tr>
<tr>
<td> <? echo $rows['comment']; ?> </td>
</tr>
</table>
<?
}
?>
谢谢您的帮助。:)