我正在研究php/mySQL/ajax留言框,并遇到了一个小问题。 在页面上,我希望将内容从最旧加载到最新,最新加载到最下面。一旦数据库开始获取大量数据,我也想限制输出以减少加载时间。php,mySQL返回前一个x行
这是当前的代码;
<?php
include_once("../includes/db.php");
include_once("../includes/functions.php");
$q="SELECT tM.*, tC.char_name as username, tC.char_id as char_id
FROM shoutbox tM JOIN characters tC
ON tC.char_id=tM.char_id
ORDER BY shout_id DESC LIMIT 25";
db_Connect();
$result=mysql_query($q);
while($row=mysql_fetch_array($result))
{
$classColor = getClassColor($row['char_id']);
echo "<span class='".$classColor."'>".$row['username']."</span>: ",nl2br($row['shout_message'])."<br />";
}
mysql_Close();
?>
我已经使用while($row=array_reverse(mysql_fetch_array($result)))
以及$result = array_reverse(mysql_query($q))
尝试,但都返回array_reverse需要被馈送阵列的错误。
到目前为止,我在网上从SQL方面发现的任何东西都已经被回答“只是相应地使用DESC或ASC”。
太棒了!谢谢。 *把这些技巧放在一起 – Jesse 2010-11-09 23:45:15