jwk811 Posted June 14, 2010 Share Posted June 14, 2010 i did this $sql="SELECT * FROM chat_messages ORDER BY message_id DESC LIMIT 10"; but i want those last 10 rows that im taking to be ordered the opposite way. if i use ASC it gives me the first 10 rows in the table Quote Link to comment Share on other sites More sharing options...
jwk811 Posted June 14, 2010 Author Share Posted June 14, 2010 nevermind i got it. i did this $sql = "SELECT * FROM chat_messages"; $result = mysql_query($sql); $num = dbNumRows($result); $last = 10; $num = $num - $last; $sql="SELECT * FROM chat_messages ORDER BY message_id ASC LIMIT $last,$num"; Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 No, that is inefficient. You only need to do a single query. The exact same question was asked just a couple days ago and a solution provided: http://www.phpfreaks.com/forums/index.php/topic,300778.msg1423631.html#msg1423631 SELECT * FROM (SELECT * FROM chat_messages ORDER BY message_id DESC LIMIT 10) as last10 ORDER BY last10.message_id ASC Quote Link to comment Share on other sites More sharing options...
fenway Posted June 15, 2010 Share Posted June 15, 2010 nevermind i got it. i did this $sql = "SELECT * FROM chat_messages"; $result = mysql_query($sql); [/quote] Yeah, horrible idea -- get back every single record just to get a count? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.