sw0o0sh Posted November 14, 2009 Share Posted November 14, 2009 In this personal forum I am coding I'm trying to grab the users online in the past 5 minutes. Every time a user goes to a new page it updates their "last_movement" field in the SQL database. Here's the query: $i=0; $sel_users_online = mysql_query("SELECT * FROM rscd_members WHERE last_movement > '" . date("Y-m-d H:i:s", time()-60*5) . "'"); while($grab_d = mysql_fetch_array($sel_users_online)){ echo "<a href='?act=profile&id=".$grab_d['id']."'>" . rank($grab_d['status']) . $grab_d['username'] . "</a>" . (($i < (($total_online) - 1)) ? ", " : null); $i++; } Here's an example of an entry stored in last_movement, which is clearly (Y-m-d H:i:s): 2009-11-13 23:32:30 Can anybody help me out here? Link to comment https://forums.phpfreaks.com/topic/181462-whats-wrong-with-this-query/ Share on other sites More sharing options...
joel24 Posted November 14, 2009 Share Posted November 14, 2009 wat type of field is "last_movement"? datetime? if so you can change that sql to $sel_users_online = mysql_query("SELECT * FROM rscd_members WHERE last_movement > NOW() - INTERVAL 5 MINUTE"); wat error are you getting? its just not selecting any members? Link to comment https://forums.phpfreaks.com/topic/181462-whats-wrong-with-this-query/#findComment-957248 Share on other sites More sharing options...
sw0o0sh Posted November 14, 2009 Author Share Posted November 14, 2009 wat type of field is "last_movement"? datetime? if so you can change that sql to $sel_users_online = mysql_query("SELECT * FROM rscd_members WHERE last_movement > NOW() - INTERVAL 5 MINUTE"); wat error are you getting? its just not selecting any members? Yeah, it's simply just not selecting any members. It's field_type is "TIMESTAMP", however I tried your method and it seems to work fine Is there anywhere I can read a manual on further working with the INTERVAL XX XX type thing? Link to comment https://forums.phpfreaks.com/topic/181462-whats-wrong-with-this-query/#findComment-957250 Share on other sites More sharing options...
joel24 Posted November 14, 2009 Share Posted November 14, 2009 hmm there doesn't seem to be a dedicated page for it, but http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add has a bit Link to comment https://forums.phpfreaks.com/topic/181462-whats-wrong-with-this-query/#findComment-957260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.