mysql query for the latest 10 results in a single query

Realalonilery

New Member
okay, my problem is a little bit more difficult than the title would tell...i have a table with messages, i load all these messages in php using a while loop.my sql query looks like this at the moment:\[code\]"SELECT * FROM messages WHERE thread_id = '" . $thread_id . "' ORDER BY date_sent"\[/code\]works fine and returns all the messages after one another, so that i have the latest message at the bottom (which is important, since my messaging module works like facebook, with a small reply field at the bottom, to let the users chat directly)now, what i'd like to have is a query that would give me only the latest 10 results in a single query.i already have the number of wanted results ($number_of_results = 10;)it'd be really cool, if i didn't have to count the rows of the result first, but rather would request the result in a single query.something like:\[code\]"SELECT * FROM messages WHERE thread_id = '" . $thread_id . "' ORDER BY date_sent LIMIT TOTAL_NUMBER_OF_ROWS_WHERE_THREAD_ID_IS_MY_THREAD_ID-$number_of_results, $number_of_results"\[/code\]is there a way to do something like this...?
 
Back
Top