|
What data type are you using for your 'last_action' and 'last_logoff_date' fields in your database?
Depending on what the type is for those columns, you may need to convert the dates from a UNIX timestamp to a MySQL date to use them properly. To do that, simply wrap your date values with a 'FROM_UNIXTIME()' function call in the query.
ie. change:
mysql_query("UPDATE users SET last_action='$date' WHERE id='$user_id'");
to:
mysql_query("UPDATE users SET last_action=FROM_UNIXTIME('$date') WHERE id='$user_id'");
and change:
mysql_query("UPDATE users SET status='offline', last_logoff_date='$date' WHERE status='online' AND last_action < '$max_last_action'");
to:
mysql_query("UPDATE users SET status='offline', last_logoff_date=FROM_UNIXTIME('$date') WHERE status='online' AND last_action < FROM_UNIXTIME('$max_last_action')");
Who knows. That date/time you gave appears to be the UNIX epoch. If I were you, I'd do two things if the above didn't work:
1) print the $date variable to screen, just to confirm that it's getting something 'useful' and that that 'useful' value is changing each time you load it.
2) in your MySQL database, change your 'last_action' and 'last_logoff_date' values to something that you know, then run the script again. If the numbers are changed back, at least you know that the query is doing SOMETHING.
Might I also just do a little bit of nitpicking? Using strings to represent state is not great (unless of course that string is being used on an enum column). Also, storing the 'last_logout_date' and the 'status' seems to be wasting space. In reality, instead of every page load changing someone's status depending on how long it's been since their last action, and then apparently using that status to determine if they are online or not, why not just look at their last action date when trying to determine their status? That way you don't need to store 'status', you don't need to store 'last_logoff_date' and you don't need to be updating those columns on each page load, either...
|