Author Topic: Load logs in DESC order backwards  (Read 381 times)

0 Members and 1 Guest are viewing this topic.

Offline EchoFoolTopic starter

  • Devotee
  • Posts: 1,058
  • Gender: Female
    • View Profile
Load logs in DESC order backwards
« on: June 10, 2010, 06:10:58 PM »
Hey,

I need help, i trying to get my chat logs to get the the lastest 30 logs so i put ORDER BY Field DESC  LIMIT 30

How ever this causes the newest log(highest) to be first.

But as its a chat room (think IRC) i want the latest message to be at the bottom and older messages above it but still only load the LIMIT of 30.

Any ideas on how to do this ?

Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 8,261
    • View Profile
Re: Load logs in DESC order backwards
« Reply #1 on: June 10, 2010, 06:36:19 PM »
I think this is what you are after:
Code: [Select]
SELECT *
 
FROM (SELECT * FROM table ORDER BY field DESC LIMIT 30) as last30
 
ORDER BY last30.field ASC
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline EchoFoolTopic starter

  • Devotee
  • Posts: 1,058
  • Gender: Female
    • View Profile
Re: Load logs in DESC order backwards
« Reply #2 on: June 10, 2010, 06:56:19 PM »
Thanks! :)

Offline James25

  • Irregular
  • Posts: 18
    • View Profile
Re: Load logs in DESC order backwards
« Reply #3 on: June 14, 2010, 02:26:49 AM »
 mjdamato  -your answer heped me as well, tough my problem was a bit different