Sleipnirx86 Posted August 29, 2010 Share Posted August 29, 2010 Hi. I am trying to figure out the best approach to pull THE most recent record for display, and ONLY the most recent one. I am really not sure how to go about doing this. Ive just started into stored procedure programming and php, but havent found anything yet on this one. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211986-pulling-last-updated-record/ Share on other sites More sharing options...
redarrow Posted August 29, 2010 Share Posted August 29, 2010 insert_id http://php.net/manual/en/function.mysql-insert-id.php Can make this really easy, just add a time stamp to the database column. paul the info out with the last data and time Quote Link to comment https://forums.phpfreaks.com/topic/211986-pulling-last-updated-record/#findComment-1104784 Share on other sites More sharing options...
jcbones Posted August 29, 2010 Share Posted August 29, 2010 You could create a timestamp column that is set to: ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Then when you create or update a record the current timestamp will be inserted into that column. A simple query would then return the result. $sql = "SELECT * FROM table ORDER BY ts DESC LIMIT 1"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { $r = mysql_fetch_assoc($result); echo $r['ts'] . ' is the most recent record!'; } PS. I may be wrong, but mysql_insert_id() will not retrieve an auto_increment id from an UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/211986-pulling-last-updated-record/#findComment-1104786 Share on other sites More sharing options...
Sleipnirx86 Posted August 29, 2010 Author Share Posted August 29, 2010 Awesome! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/211986-pulling-last-updated-record/#findComment-1104791 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.