Hi Guys,
Sorry for another post, but I have a different question and I'm struggling to figure out the best way to do it.
I'm writing a messaging app, and when viewing messages, I want users to select how many messages are displayed. When viewing, the messages are displayed from oldest to newest. So as you scroll down, you are scrolling down to newer messages.
This is normal sorting order as older messages are displayed first (because they were entered first).
How would I display the newest 15 records? My thoughts are to Select TOP 15 and Order it descending, so that it grabs the last 15 records. But that leaves the record set in reverse order, displaying the newest message at the top, not the bottom. So I need to run that query, then apply another order by, DESC.. which would flip the record set around, grab the top 15 (newest 15) then flip the record set around again. But I can't get the syntax to work ..
Here's a shortened version of what I have.. what's wrong?
Sorry for another post, but I have a different question and I'm struggling to figure out the best way to do it.
I'm writing a messaging app, and when viewing messages, I want users to select how many messages are displayed. When viewing, the messages are displayed from oldest to newest. So as you scroll down, you are scrolling down to newer messages.
This is normal sorting order as older messages are displayed first (because they were entered first).
How would I display the newest 15 records? My thoughts are to Select TOP 15 and Order it descending, so that it grabs the last 15 records. But that leaves the record set in reverse order, displaying the newest message at the top, not the bottom. So I need to run that query, then apply another order by, DESC.. which would flip the record set around, grab the top 15 (newest 15) then flip the record set around again. But I can't get the syntax to work ..
Here's a shortened version of what I have.. what's wrong?
Code:
SELECT * FROM (SELECT TOP 15 *
FROM tbl_member_messages
WHERE recipient_id = "#session.myid#" and sender_id = "#member_b_id#"
ORDER BY SENT_DATE DESC) ORDER BY SENT_DATE DESC
Last edited: