dongyi5570 2012-09-04 06:02
浏览 28
已采纳

如何从我的应用程序中查看谁在线?

I have made a server - client app in android with php and mysql. When any new user registers and clicks on submit button then his/her information goes to php and gets stored in mysql database that is on the internet.

And then i have get that list of peoples in listview who are registered before in my app and in listview i can see all that people but now i want to add a functionality that can check who is online right now in my app. I will make two buttons ONLINE and OFFLINE. When i press the ONLINE buttons only those people should be display who are using this app right now.

I have also search this in web but i dint find any proper result, so please anybody who have made this before please give me some idea or link of tutorial regarding this. Thank you for your time.

  • 写回答

1条回答 默认 最新

  • dongshao5573 2012-09-04 06:32
    关注

    In your DB, add a field called (last_login as DateTime). This field is updated each time the user logins to the application, and start a new session. Use a query similar to the below.

    UPDATE tbl_users SET last_login=NOW() WHERE ID_FIELD = $USER_ID

    Whenever a user clicks the (Who is Online) button, a PHP script is called that queries all the user where the last_login field contains a value for example less than 3 hours.

    The query you can use

    SELECT * FROM tbl_users WHERE TIMESTAMPDIFF(HOUR,last_login,NOW()) <=3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog