There is a request of this type

SELECT a.id, a.author, a.txt, a.timestamp, b.log, b.em FROM txt_mesg a LEFT JOIN users b ON b.id = a.author WHERE a.tid = '".$id."' ORDER BY a.timestamp DESC LIMIT 12" 

Messages are displayed in decreasing order of time, but in ascending order.

How can such sorting be done?

  • change ORDER BY a.timestamp DESC to ORDER BY a.timestamp ASC - ragmon

2 answers 2

Remove DESC or replace it with ASC (but this is not necessary)

 SELECT a.id, a.author, a.txt, a.timestamp, b.log, b.em FROM txt_mesg a LEFT JOIN users b ON b.id = a.author WHERE a.tid = '".$id."' ORDER BY a.timestamp LIMIT 12" 

    You seem to need to also select the last 12 messages, but at the same time change their order. is solved by another select level with a different sort:

     SELECT * FROM ( SELECT a.id, a.author, a.txt, a.timestamp, b.log, b.em FROM txt_mesg a LEFT JOIN users b ON b.id = a.author WHERE a.tid = '".$id."' ORDER BY a.timestamp DESC LIMIT 12 ) X ORDER BY timestamp