我有以下 PHP 脚本:
<?php
header('Content-type: text/xml');
mysql_connect('localhost', 'root', 'root');
mysql_select_db('sportApp');
if ($_REQUEST['past']) {
$result = mysql_query('SELECT * FROM chatitems WHERE id > ' . mysql_real_escape_string($_REQUEST['past']) . ' ORDER BY added LIMIT 50');
} else {
$result = mysql_query('SELECT * FROM chatitems ORDER BY added LIMIT 50');
}
?>
<chat>
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<message added="<?php echo( $row['added'] ) ?>" id="<?php echo( $row['id'] ) ?>">
<user><?php echo( htmlentities($row['user']) ) ?></user>
<text><?php echo( htmlentities($row['message'])) ?></text>
<subtext><?php echo( htmlentities($row['subtext'])) ?></subtext>
<image><?php echo( htmlentities($row['image']) ) ?></image>
<ytvideo><?php echo( htmlentities($row['ytvideo']) ) ?></ytvideo>
</message>
<?php
}
mysql_free_result($result);
?>
</chat>
我在本地主机和 MYSQL 表上存储了七个元素,其中一个是 TIMESTAMP
,当我插入新行时,时间被保存。问题是我如何订购我的显示按最后添加的行分页[我希望首先显示插入的最后一行,请参阅代码]。请帮忙!
最佳答案
使用 DESC 反转顺序:
ORDER BY added DESC
关于php - 插入的最后一行首先显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7458059/