sd21 Posted August 2, 2008 Share Posted August 2, 2008 I'm having a lot of trouble here and was hoping someone could help me. I'm trying to retrieve the last 5 rows from a table but can't figure out how to do it for the life of me. The table has only 3 columns and are identified by an auto incrementing number. I used the following select statement but it is still returning the top 5 rows instead of the bottom 5 rows. $query = "SELECT * FROM comms ORDER BY 'commid' DESC LIMIT 6"; 'commid' is the auto incrementing number. Can anyone tell me what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/117791-need-help-retrieving-the-last-5-rows-from-a-table/ Share on other sites More sharing options...
ratcateme Posted August 2, 2008 Share Posted August 2, 2008 i am no expert on mysql but i think it matters weather you use ' or ` try this $query = "SELECT * FROM `comms` ORDER BY `commid` DESC LIMIT 6"; Quote Link to comment https://forums.phpfreaks.com/topic/117791-need-help-retrieving-the-last-5-rows-from-a-table/#findComment-605841 Share on other sites More sharing options...
.josh Posted August 2, 2008 Share Posted August 2, 2008 desc counts down so if commid was like 100, 12, 42, 20, 52 it would return 100 52 42 20 12 Quote Link to comment https://forums.phpfreaks.com/topic/117791-need-help-retrieving-the-last-5-rows-from-a-table/#findComment-605843 Share on other sites More sharing options...
.josh Posted August 2, 2008 Share Posted August 2, 2008 i am no expert on mysql but i think it matters weather you use ' or ` try this $query = "SELECT * FROM `comms` ORDER BY `commid` DESC LIMIT 6"; you do not need backticks on column or table names unless they are named the same as reserved words (which you shouldn't be doing) Quote Link to comment https://forums.phpfreaks.com/topic/117791-need-help-retrieving-the-last-5-rows-from-a-table/#findComment-605844 Share on other sites More sharing options...
sd21 Posted August 2, 2008 Author Share Posted August 2, 2008 i am no expert on mysql but i think it matters weather you use ' or ` try this $query = "SELECT * FROM `comms` ORDER BY `commid` DESC LIMIT 6"; Wow, thanks a bunch man, that did it. You're a real life saver. Quote Link to comment https://forums.phpfreaks.com/topic/117791-need-help-retrieving-the-last-5-rows-from-a-table/#findComment-605845 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.