daveh33 Posted December 27, 2007 Share Posted December 27, 2007 So far I have the following query - I am trying to get the results where chatroom=$id & where the lastlogin was up to 30mins ago $query = mysql_query("SELECT * from users WHERE chatroom='$id' && lastlogin='$lastlogin") or die (mysql_error()); I have a field lastlogin in the database - but how do I do the time validation for the last 30 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/ Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 What does your lastlogin field contain, what type of time stamp? Hopefully Unix. Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/#findComment-424315 Share on other sites More sharing options...
daveh33 Posted December 27, 2007 Author Share Posted December 27, 2007 Example: 2007-12-27 21:45:00 Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/#findComment-424316 Share on other sites More sharing options...
pocobueno1388 Posted December 27, 2007 Share Posted December 27, 2007 Try SELECT * FROM users WHERE chatroom='$id' AND lastlogin > (NOW() - INTERVAL 30 MINUTE) Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/#findComment-424319 Share on other sites More sharing options...
daveh33 Posted December 27, 2007 Author Share Posted December 27, 2007 It doesnt given any errors - but it doesnt give any results either Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/#findComment-424324 Share on other sites More sharing options...
pocobueno1388 Posted December 27, 2007 Share Posted December 27, 2007 Are you sure you have any results with the lastlogin field is less than 30 minutes ago AND has the correct chatroom ID? Play with the query in your database and see if you can get any results by changing things around that you know will give results. Quote Link to comment https://forums.phpfreaks.com/topic/83403-time-based-mysql-query/#findComment-424362 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.