我正在网上借一个论坛。我希望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();
?>
答案 0 :(得分:0)
更改您的查询,以按您希望的顺序检索帖子。根据你的帖子做出猜测我会说你的查询看起来应该更像:
$sql="SELECT * FROM `forum_question` ORDER BY datetime DESC";