Last row inserted to be displayed first
NickName:Jamal Tyson Ask DateTime:2011-09-18T05:51:47

Last row inserted to be displayed first

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 an 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!

Copyright Notice:Content Author:「Jamal Tyson」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7458059/last-row-inserted-to-be-displayed-first

More about “Last row inserted to be displayed first” related questions

Last row inserted to be displayed first

I have the following PHP script : &lt;?php header('Content-type: text/xml'); mysql_connect('localhost', 'root', 'root'); mysql_select_db('sportApp'); if ($_REQU

Show Detail

Find id of last inserted row

I have to simple tables in SQLite in my app and I need to insert into my tables values, but when I insert into the first I need to find value id ( primary key first column ) and that to be foreign ...

Show Detail

Get First row/id & Last row/id of total inserted result set, instead of only last id/row. SQL,PHP,Codeigniter

function storeReachout($reachoutInfo) { $result = $this-&gt;db-&gt;insert('tbl_youtube',$reachoutInfo); // $Frow = $result-&gt;first_row('array'); // $Lrow = $result-&gt;last_row('arra

Show Detail

DataGridView show first row in half but last row complete

In the red box you can see the last row, whose upper half is visible. I want to show the last row full and the first (upper-most displayed) row in half. AFAIK whatever you do (scroll, change curr...

Show Detail

Mysql last inserted row Id

In Mysql I am inserting a row with Insert command in a table of mysql , now I want the Id of last row Inserted , I am using SELECT LAST_INSERT_ID() ; But it gives me 0 as output every time . Ple...

Show Detail

How to get last inserted row in SQlite android

I want to get the last inserted row's primary key value which is set automatically(AUTO INCREMENT). I searched over the S/O and found answers for last row_id. But I need the last inserted row's val...

Show Detail

How to get last inserted row from table?

My table is like below: Id Data Date A abc 2016-10-01 00:00:00 A def 2015-05-20 00:00:00 B xyz 2014-05-20 00:00:00 B uvw 2016-10-01 00:00:00 B rst 2015-10-01 00:00:00 I

Show Detail

how to write last inserted data first on a excelsheet?

i am writing mongodb data on a excelsheet using apache poi but its writing first inserted data on a first row of a excel but i need last inserted data on a first row i want to print last to first on

Show Detail

How to auto select the last inserted row in JTable?

Since JTable could be sorted. How do I set it auto select the last inserted row whenever a row is inserted? Thanks

Show Detail

Can I get columns of last inserted row?

Hi I'm using Codeigniter and would love a solution in CI but can suffice with mysqli or PDO. I was wondering if there is a way to get a column of the last inserted row in MySql 5.1.54 The reason ...

Show Detail