Drezard Posted March 7, 2007 Share Posted March 7, 2007 alright heres my code: $online = 1; $query = "SELECT * FROM user_ids WHERE online='$online'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); $timestamp = date(YmdGi); $old_timestamp = $timestamp - 5; $query = "SELECT user FROM user_ids WHERE online='$online'"; $result_user = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "SELECT timestamp FROM user_ids WHERE online='$online'"; $result_time = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); for ($i = 0; $i <= $count; $i++) { while ($row_time = mysql_fetch_array($result_time)) { $user_timestamp = $row_time[i]; while ($row_user = mysql_fetch_array($result_user)) { $user = $row_user[i]; if ($old_timestamp >= $user_timestamp) { $online = 0; $query = "UPDATE user_ids SET online='$online' WHERE user='$user'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); } } } } echo "Users online: $count"; Now, this is my code.... In the database I have something like this: TABLE user_ids: USER TIMESTAMP ONLINE peter 200703071932 0 paul 200703071952 1 john 200703071532 0 Now, I want my script to go through my database (in the other parts of code it connects to the database and all of that... its just the output that i dont like) Its currently 2035 where i live. Now, I want my script to search through the database for all the users that have an online status of 1... then search the database and get the timestamp... if the timestamp is greater then 5 mins old. I want the script to change the users online status to 0 (offline). So, I should get a count of all the users that have a timestamp that is newer then 5 mins. Now, what is wrong with my above script? (The script is currently running on www.wintersword.com/users_online.php if you would like to see the output im getting.) - Cheers, Daniel Please HELP... I dont care if i have to answer a few questions, so what exactly do u want? or such... Quote Link to comment Share on other sites More sharing options...
btherl Posted March 7, 2007 Share Posted March 7, 2007 Would this query do it? $query = "UPDATE user_ids SET online = 0 WHERE timestamp < '$old_timestamp' AND online = 1"; Then to count the users online: $query = "SELECT count(*) FROM user_ids WHERE online = 1"; Quote Link to comment Share on other sites More sharing options...
Drezard Posted March 7, 2007 Author Share Posted March 7, 2007 Still more problems... $timestamp = date(YmdGi); $old_timestamp = $timestamp - 5; $query = "UPDATE user_ids SET online = 0 WHERE timestamp < '$old_timestamp' AND online = 1"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "SELECT * FROM user_ids WHERE online='$online'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); echo "Users online: $count"; is that what it should be? Quote Link to comment 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.