Skip to content

How to reverse fetch assoc in PHP?

while($row = mysql_fetch_assoc($result)){
    $items[] = $row;

$items = array_reverse($items ,true);

foreach($items as $item){
   echo $item['time']." - ".$item['username']." - ".$item['message'];

//another option can be

$query = mysql_query("SELECT * FROM (
                      SELECT time, username, message
                      FROM messages ORDER BY time 
                      DESC LIMIT 10) result 
                      ORDER BY time ASC   
See also  Java code snippet - How to read html file from resource folder from spring project by using maping?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.