我试图弄清楚如何找到在时间范围内登录的用户?
案例:
登录数据示例表
public bool OnTouch(View v, MotionEvent e)
{
if (GetDisplayedDrawable() != null)
{
int x = (int)e.GetX();
int y = (int)e.GetY();
int left = (loc == Location.LEFT) ? 0 : Width - PaddingRight - xD.IntrinsicWidth;
int right = (loc == Location.LEFT) ? PaddingLeft + xD.IntrinsicWidth : Width;
bool tappedX = x >= left && x <= right && y >= 0 && y <= (Bottom - Top);
if (tappedX)
{
if (e.Action == MotionEventActions.Up)
{
Text = "";
if (listener != null)
{
listener.DidClearText();
}
}
return true;
}
}
if (l != null)
return l.OnTouch(v, e);
return false;
}
public void OnFocusChange(View v, bool hasFocus)
{
if (hasFocus)
SetClearIconVisible(!string.IsNullOrEmpty(Text));
else
SetClearIconVisible(false);
if (f != null)
f.OnFocusChange(v, hasFocus);
}
如果user1和user2在19:00到20:00之间在线,而user3没有在线,我想知道。
在这种情况下,数据存储在mysql中,并使用php输出数据。
连连呢?
答案 0 :(得分:0)
要查找在特定时间段内登录的所有用户,您需要检查time_from
是否小于期限结束,和 time_to
大于一开始。
使用PDO的一个简单示例:
$sql = 'SELECT user FROM login_data WHERE time_from <= ? AND time_to >= ? GROUP BY user';
$stmt = $pdo->prepare($sql);
$stmt->execute([$end_time, $start_time]);
$users = $stmt->fetchAll();
这不会让您在指定的时间段内未登录哪些用户,但理论上您可以将结果加入到您的用户表中以查找。