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
https://forums.phpfreaks.com/topic/157951-last-seen/
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
https://forums.phpfreaks.com/topic/157951-last-seen/#findComment-833306
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
https://forums.phpfreaks.com/topic/157951-last-seen/#findComment-833746
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.