0

I have table with name "Comments", there is few columns: ID, User, author, date, post

What I want is to show last 10/20 comments, where newest is from top, all by vertically.

4

4 回答 4

2

那将是一个与数据库相关的问题,通常在 SQL 查询中进行排序。假设您的评论表具有给定的结构,它将是:

SELECT ID, user, author, date, post FROM Comments ORDER BY date DESC LIMIT 0,10
于 2012-12-26T13:17:59.090 回答
1

将此附加到您的 sql 语句order by date desc limit 0,20 这应该给您最新的 20 条评论

如果还想显示接下来的20条结果也可以添加OFFSET 20,这样可以帮助你达到加载下一页的效果。

要显示评论,您需要显示它们

<?php
$result=mysql_query("SELECT ID, user, author, date, post TOP number column_name(s) * FROM comments ORDER BY date DESC LIMIT 0,10");
while($row=mysql_fetch_array($result))
 {
   echo $row[4];
 }
 ?>
于 2012-12-26T13:18:59.357 回答
0

limit在 mysql 查询或 jquery 中都prepend()可以。

于 2012-12-26T13:17:36.280 回答
0
SELECT TOP number column_name(s)
FROM table_name ORDER BY column_name(s) ASC|DESC
于 2012-12-26T13:19:01.993 回答