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很陌生。 –