开发者

Last row inserted to be displayed first

开发者 https://www.devze.com 2023-04-05 09:34 出处:网络
I have the following PHP script : <?php header(\'Content-type: text/xml\'); mysql_connect(\'localhost\', \'root\', \'root\');

I have the following PHP script :

<?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>

I have stored on my localhost and MYSQL table with seven elements,one of they is a开发者_如何学运维n TIMESTAMP,when i insert a new row the time is saved.The question is how can i order my displaying page by the last rows added [ I Want the last row inserted to be displayed first, see the code]. Help please!


Reverse the order using DESC:

ORDER BY added DESC
0

精彩评论

暂无评论...
验证码 换一张
取 消