physaux Posted April 10, 2010 Share Posted April 10, 2010 Hey guys I have a table about my users. One of the entries is "last_login", which is as so: http://img340.imageshack.us/img340/3986/picture2hb.png I regularly get data from this. I would like to update the timestamp thought. I'm not sure exactly how to do this. It is my understanding that it will update itself if I edit the record. But I don't want to edit the record, I mainly just read it. So is there any 'command' that I could run to update to the current time at the time of running this command? There's probably a simply mysql line to MODIFY the timestamp, but I've been searching for hours now and I can't find how to do it :'( :'( Hope that makes sense. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/198180-how-can-i-update-my-timestamp/ Share on other sites More sharing options...
bateman Posted April 11, 2010 Share Posted April 11, 2010 What you want to do is run an update, targeted just for that field. This is what I run (for last login) $lastlogin = date("Y-m-d H:i:s"); $sql="update users set lastlogin='$lastlogin' WHERE username='$un'"; Of course you can change the date field to the timestamp of your preference. Quote Link to comment https://forums.phpfreaks.com/topic/198180-how-can-i-update-my-timestamp/#findComment-1039835 Share on other sites More sharing options...
andrewgauger Posted April 11, 2010 Share Posted April 11, 2010 Well, from what I have seen, there is no magic mysql for using a trigger select or automating timestamp updates on select. What I can tell you is you can throw a counter into your login database (ALTER TABLE login ADD COLUMN counter int) and you can extend your sql to "UPDATE login SET counter=counter+1 where user_id=$var" to use the functionality of the ON UPDATE. Otherwise, your just going to have to execute an UPDATE login SET last_login=".time(); (which does seem simpler.) Quote Link to comment https://forums.phpfreaks.com/topic/198180-how-can-i-update-my-timestamp/#findComment-1039837 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.