0

我正在从网上借来的论坛制作论坛。我希望 main_forum 页面首先显示最近发布的主题,然后是最近发布的第二个,依此类推。我的 main_forum.php 代码是这样的:

<?php
require_once 'includes/overall/header.php';
$sql="SELECT * FROM `forum_question` ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<h1>Forum</h1>
<table width=700 class="outer">
<tr>
<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
// Start looping table row
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<?php echo $rows['id']; ?>"><?php echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td>
</tr>
<?php
// Exit looping and close connection 
}
mysql_close();
?>
<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
<?php
require_once 'includes/overall/footer.php';
ob_end_flush();
?>
4

1 回答 1

0

更改您的查询以按照您想要的顺序检索您的帖子。根据您的帖子进行猜测,我会说您的查询应该更像:

$sql="SELECT * FROM `forum_question` ORDER BY datetime DESC";
于 2013-04-15T02:29:15.383 回答