undertaker Posted March 7, 2011 Share Posted March 7, 2011 Hi, i have simple question about mysql select in php which i cant figure out. For example i have table Cars and categories manufacturer, type and year SO whenever i normally print out the data with loop, all posts are read from the database and printed out. How to get just the last post? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/ Share on other sites More sharing options...
Vebut Posted March 7, 2011 Share Posted March 7, 2011 Do you have an increment value (id?) for each car, or maybe a timestamp? SELECT * FROM table ORDER BY id DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/#findComment-1183969 Share on other sites More sharing options...
fenway Posted March 7, 2011 Share Posted March 7, 2011 Do you have an increment value (id?) for each car, or maybe a timestamp? SELECT * FROM table ORDER BY id DESC LIMIT 1 Yeah, don't use id for this kind of thing -- a timestamp is the only useful column in this case. Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/#findComment-1184034 Share on other sites More sharing options...
undertaker Posted March 7, 2011 Author Share Posted March 7, 2011 thnx guys Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/#findComment-1184103 Share on other sites More sharing options...
Vebut Posted March 8, 2011 Share Posted March 8, 2011 The last post should have the highest incremented value. Timestamps can be manipulated so I would rather use the increment before using the timestamp (as these may not be unique). Unless you want to find the latest car by it's release date. Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/#findComment-1184371 Share on other sites More sharing options...
fenway Posted March 8, 2011 Share Posted March 8, 2011 Yeah, but the IDs are arbitrary, and if I insert something for the past or the future, the id is meaningless. Quote Link to comment https://forums.phpfreaks.com/topic/229867-select/#findComment-1184486 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.