我有一个评论表,其中存储了所有评论,我想显示最近20条评论
$query="SELECT * FROM comment WHERE answerid=$answerid ORDER BY time DESC LIMIT 20";
它给了我最后20个但是从上到下,但我想让它们一直到最顶层。最后评论(按时间)应该最后显示
$result = mysql_query($query);
$newresult = array_reverse($result);
while( $row = mysql_fetch_array($newresult) ) {
//my code
echo $row['content'];
}
但这不起作用?
答案 0 :(得分:7)
尝试:
SELECT * FROM (
SELECT * FROM comment WHERE answerid=$answerid ORDER BY time DESC LIMIT 20
) d ORDER BY time
答案 1 :(得分:0)
$query="SELECT * FROM comment WHERE answerid=$answerid ORDER BY time ASC";
答案 2 :(得分:0)
ORDER BY id DESC LIMIT 20
如果列id为auto_increment,则此方法正常。 您也可以在代码中将DESC更改为ASC!