Joshua F Posted September 25, 2010 Share Posted September 25, 2010 I have a database with Users as a table. It has the normal stuff, id, username, password, and I have anther in it called lastactive. It is DATETIME, and I am wondering how I would make a sql query select the users in the database 'users' and see who has been active in the past 15 mins. What I am asking is how I could do this, and would it be better to use a different structure other then DATETIME. Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/ Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 Tested this locally, and it should produce the results you're after. SELECT `whatever` from `Users` WHERE ( TIMESTAMPDIFF(MINUTE, `lastactive`, NOW() ) < 15 ) Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115595 Share on other sites More sharing options...
Joshua F Posted September 25, 2010 Author Share Posted September 25, 2010 So, with that, should I use DATETIME or something else, or does it matter? Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115597 Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 That is made to work with the DATETIME field data type. I almost never use unix timestamps, especially in a database. Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115601 Share on other sites More sharing options...
Joshua F Posted September 25, 2010 Author Share Posted September 25, 2010 Alright, thanks. Got it working. Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115603 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Share Posted September 25, 2010 Okay I did this, but mine is still bringing back no results. Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115631 Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Share Posted September 25, 2010 Nevermind. I just had to remove the '' around my database field name and now it works. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/214375-active-in-15-mins/#findComment-1115632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.