0
我目前有一个MySQL数据库,其中包含任何留言在我的网页上。在列表的底部如何对这些注释进行排序,以便最近出现在顶部?
<?
$con = mysql_connect("localhost","theshitp_user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("theshitp_posts", $con);
$query = "SELECT * FROM `userposts` LIMIT 0 , 30";
$comments = mysql_query($query);
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$comment = $row['comment'];
$timestamp = $row['timestamp'];
$comment = htmlspecialchars($row['comment'],ENT_QUOTES);
echo " <div style='text-align: center; border-style: solid; border-weight: 2px; border-radius: 5px; padding: 10px; margin-bottom: 10px; margin-left: 50px; margin-right: 50px;'>
<h3>$comment</h3><br />
$timestamp
</div>
";
}
mysql_close($con);
?>
这个帖子的最新评论:我然后写入下面的脚本,使他们出现在页面上。我如何修改这个脚本使它按照最新的顺序排序评论?
在任何日期时间字段上使用order by。 –
这样做的代码会是什么样子?我对SQL很陌生。 –