繁体   English   中英

最后插入的行将首先显示

[英]Last row inserted to be displayed first

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM