wwfc_barmy_army Posted July 30, 2009 Share Posted July 30, 2009 Is there an easy way/SQL comment to get the last entered record from a table with a certain userID? Thanks for any advice. Link to comment https://forums.phpfreaks.com/topic/168140-get-last-record-from-table-with-certain-user_id/ Share on other sites More sharing options...
gevans Posted July 30, 2009 Share Posted July 30, 2009 If you're table has an auto_increment id field it can be done with something like this... SELECT `a_field` FROM `a_table` WHERE `userID`=$your_var ORDER BY `id` DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/168140-get-last-record-from-table-with-certain-user_id/#findComment-886806 Share on other sites More sharing options...
wwfc_barmy_army Posted July 30, 2009 Author Share Posted July 30, 2009 Unfortunatly not, the table has duplicates of user_id, but i used the same concept and tried: SELECT * FROM table WHERE id= " . $user_id . " ORDER BY date DESC LIMIT 1 I have a date column, but my next question is will it work properly? It does in the test account I have but does it actually see it as a date or just a big number? Thanks for any advice. Link to comment https://forums.phpfreaks.com/topic/168140-get-last-record-from-table-with-certain-user_id/#findComment-886824 Share on other sites More sharing options...
kickstart Posted July 30, 2009 Share Posted July 30, 2009 Hi It sees it as a very big number. Concept will work (although best not to have a column called date) unless somehow you can have records with the same time / time for the user. All the best Keith Link to comment https://forums.phpfreaks.com/topic/168140-get-last-record-from-table-with-certain-user_id/#findComment-886827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.