mansoor323 Posted September 4, 2009 Share Posted September 4, 2009 i have problem fetching last record from the database... i'm using a auto increment id column in my table and in that column i'm updating values time to time...so i cannot use ORDER BY id DESC..besides i cannot use another auto increment column in MYSQL ddatabase to use the above query.... can anybody tell me how to do it?? Quote Link to comment https://forums.phpfreaks.com/topic/173099-how-to-fetch-last-entered-record-from-the-databse/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 4, 2009 Share Posted September 4, 2009 The last record entered (INSERTED) can be found using the ORDER BY id DESC ... However, if what you want is the last record UPDATED, you would need to have a column that holds the date/time that the record was updated. If you use a mysql TIMESTAMP (not to be confused with a Unix Timestamp) you can set it up so that it will automatically be updated when you do an UPDATE query - http://dev.mysql.com/doc/refman/5.0/en/timestamp.html Quote Link to comment https://forums.phpfreaks.com/topic/173099-how-to-fetch-last-entered-record-from-the-databse/#findComment-912377 Share on other sites More sharing options...
kickstart Posted September 4, 2009 Share Posted September 4, 2009 i'm using a auto increment id column in my table and in that column i'm updating values time to time...so i cannot use ORDER BY id DESC.. I presume that you are concerned that another system / page may have inserted a record before you try and retrieve it. You can use mysql_insert_id to get the last row you inserted. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/173099-how-to-fetch-last-entered-record-from-the-databse/#findComment-912394 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.