这是我用来查看论坛内容的简单php代码。问题是,它在我的一台笔记本电脑上工作正常,但在第二次它不显示输出。这个php代码有什么问题?
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#E6E6E6"><? echo $rows['id']; ?></td>
<td bgcolor="#E6E6E6"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['datetime']; ?></td>
</tr>
我检查了一切,他们似乎很好。数据存在于数据库中,但未在论坛中显示。有人可以帮我吗? 操作系统:win7
请发布您的所有代码和数据库结构。 – 2011-03-02 08:49:09
我看不到'$ tbl_name'在哪里定义。您是在笔记本电脑上运行此代码还是在其他位置托管? – 2011-03-02 08:49:11
也许短标签被禁用。更改<? echo $ rows ['id']; ?>到<?php echo $ rows ['id']; ?>和所有以<?开头的行。到<?php – smottt 2011-03-02 08:49:25