插入的最后一行首先显示

时间:2011-09-17 21:51:47

标签: php mysql

我有以下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>

我已经在我的localhost和MYSQL表中存储了七个元素,其中一个是TIMESTAMP,当我插入新行时,时间被保存。问题是如何通过以下方式订购我的显示页面最后一行添加[我希望插入的最后一行首先显示,请参阅代码]。求救!

1 个答案:

答案 0 :(得分:3)

使用DESC撤消订单:

ORDER BY added DESC