Jump to content

Last Seen


N-Bomb(Nerd)

Recommended Posts

Hello, I'm creating a last seen script for my website and ran into a bit of trouble. I'm able to store when the user was last seen, and even pull that information from the database, however I have no idea how to use the DATEDIFF function with mySQL.

 

Here's my test code so far.. Also let me know if you see a way I could improve this.

 

function test() {
if (mySQLConnect('host', 'db', 'username', 'password') == true) {
	$Query = mysql_fetch_array(mysql_query("SELECT * FROM TimeTable WHERE username = 'workgoddamnit'"));

	echo $Query['username'] . ' was last seen ' . ????

}
}

 

I'm able to format the date myself, heh just I don't know how to use DATEDIFF properly.. any help is much appreciated.

Link to comment
Share on other sites

Hi

 

Put it in something like this:-

 

function test() {

  if (mySQLConnect('host', 'db', 'username', 'password') == true) {

      $Query = mysql_fetch_array(mysql_query("SELECT username, last, DATEDIFF(last,NOW()) TimeSinceLastTouchedInDays FROM TimeTable WHERE username = 'workgoddamnit'"));

 

      echo $Query['username'] . ' was last seen ' . $Query['TimeSinceLastTouchedInDays '];

 

  }

}

 

This will return the number of days since the were last seen as a field called TimeSinceLastTouchedInDays .

 

All the best

 

Keith

Link to comment
Share on other sites

Keith,

 

I've tried the code that you've posted, and I can't seem to get it to work. Usually if I mess around enough with the code I can get it to work, this doesn't seem to be the case this time. Any suggestions on what I should do?

 

I know this isn't a good reply because I didn't reply any output simply for the fact that there was none.

Link to comment
Share on other sites

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.