doulan4371 2012-12-05 09:03
浏览 35
已采纳

用MySQL或PHP计算以分钟为单位的时差量?

I save users sing-in information using the fields below:

user_id, login_date, login_time, status

After each attempting for sign-in, a record will insert into database using true or false status. I want to lock user if he/she has 3 failed logins in the last 3 minutes. So I need to use the current time and calculate its difference with 3 last records of table in minute format.

My questions are:
1- Which one is better to do this time calculation? PHP or MySQL?
2- Depends on your suggestion, which function is better for it?

Thank you.

  • 写回答

4条回答 默认 最新

  • dsh1102 2012-12-05 09:17
    关注

    Following query returns all User_Id's according your conditions:

    select user_id from t 
    where login_date= CURDATE() 
          and login_time>TIMESTAMPADD(MINUTE,-3,CURTIME())
          and status = 'f'
    group by user_id 
    having count(*)>3
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 NTQQ内存操作,懂的私
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭
  • ¥15 如何在APPdesigner中输入矩阵并进行计算输出?
  • ¥15 Matlab读取根元素出错
  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片