Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7795503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:05:17+00:00 2026-06-01T23:05:17+00:00

//get the messages from the database $messagesID_query = mysql_query(SELECT messageID, posterID, messageTime, message FROM

  • 0
//get the messages from the database
$messagesID_query = mysql_query("SELECT
                                   messageID,
                                   posterID,
                                   messageTime,
                                   message
                                 FROM
                                   chat_messages
                                 ORDER BY
                                   messageTime DESC
                                 LIMIT
                                   20");

The above mysql_query returns the latest 20 entries from a table. However, I ideally need to reverse the resource before fetching the rows.

At the moment, I run 2 loops:
1 – one to fetch all the results in a php array
2 – then another to process the array to print once reversed.

I am trying to optimize the way this works… is it possible to reverse the mysql resource before i start fetching the rows so i do not have to reverse the array in php?

Or, is there a way that I have over looked of rewriting the query to return the said rows in reverse order.. but still getting the latest 20 results as the above does?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:05:19+00:00Added an answer on June 1, 2026 at 11:05 pm

    This is best done in the query. Wrap the whole thing in a subquery and reorder that back into ascending order by messageTime. This could save considerable CPU resources on the database server over looping a bunch of calls to mysql_data_seek() to fetch rows backward on a larger rowset than your 20.

    SELECT * FROM 
    (
      SELECT
        messageID,
        posterID,
        messageTime,
        message
      FROM
      chat_messages
      /* Subquery is used to get the most recent 20 by messageTime */
      ORDER BY messageTime DESC
      LIMIT 20
    ) subq
    /* Reorder the result of the subquery to put them back into ascending order */
    ORDER BY messageTime ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to get error messages from a WF4 workflow back
we're have a client that needs to get interactive messages from a server, from
I have to use several SOAP messages to get data from a web service.
I get this error message from a Ghostscript call: Error: /syntaxerror in -file- Operand
If i wanted to get message for ViewData from resource file, depending on the
I'm using Sencha Touch (ExtJS) to get a JSON message from the server. The
We have a lot of queries select * from tbl_message that get stuck on
im creating a messaging feature that gets the latest messages from a database every
I am trying to get all Inbox Messages using ContentResolver based on message ids
I need to get 1000 rows from a database, and at the same time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.