用户在时间范围内登录

时间:2018-02-23 23:08:07

标签: php mysql time

我试图弄清楚如何找到在时间范围内登录的用户?

案例:
登录数据示例表

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输出数据。

连连呢?

1 个答案:

答案 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();

这不会让您在指定的时间段内登录哪些用户,但理论上您可以将结果加入到您的用户表中以查找。

相关问题