Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/198180-how-can-i-update-my-timestamp/
Share on other sites

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.

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.) 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.