shirvo Posted February 11, 2007 Share Posted February 11, 2007 I have a table and in the id field i want to find out how many there are in it. The whole reason for this is because i want to find the highest 4 so i can display the 4 newest members. Link to comment https://forums.phpfreaks.com/topic/38001-find-out-how-many-in-a-table/ Share on other sites More sharing options...
wildteen88 Posted February 11, 2007 Share Posted February 11, 2007 Order the id column in descending order and limit the results by 4. That will grab the 4 newest members from your table. SELECT * from `members_tbl` ORDER By id DESC LIMIT 4 Link to comment https://forums.phpfreaks.com/topic/38001-find-out-how-many-in-a-table/#findComment-181878 Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Don't rely on an auto-incrementing primary key to determine the latest records (that is not there intended purpose, and it will prove unreliable), put a timestamp in your table then order by that with a limit of 4. eg; SELECT username FROM users ORDER BY tstamp DESC LIMIT 4; Link to comment https://forums.phpfreaks.com/topic/38001-find-out-how-many-in-a-table/#findComment-181879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.