我有一个表,用于存储UNIX格式的用户的上次登录时间。我想获取至少4天前登录的所有用户的信息。这是数据库的图像:
我试过这个:
$time = sql_query("select * from ".tb()."accounts");
$pp = sql_fetch_array($time);
$tp = $pp['lastlogin'];
$ts = strtotime('-4 day',time());
$tg = $tp > $ts;
$res = sql_query("select f.fid from ".tb()."friends as f left join ".tb()."accounts as u on u.id=f.fid where f.uid='{$client['id']}' order by {$tg} desc limit 50");
但它似乎没有用。是否有一种简单的方法可以显示超过4天前登录的所有用户的信息?
答案 0 :(得分:2)
选择过去最后一次登录超过4天的行:
SELECT
...
WHERE
FROM_UNIXTIME(lastlogin) < CURRENT_TIMESTAMP - INTERVAL 4 DAY
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html