jemgames Posted July 27, 2007 Share Posted July 27, 2007 Hey. I'm having trouble with my users online section. Here is the code for the users online display: $time = time() - 60 * 15; $mems = "SELECT * FROM members WHERE last_activity <= $time"; $mems = mysql_query($mems); $cnt = mysql_num_rows($mems); for ($i = 0; $i < $cnt && $rows = mysql_fetch_assoc($mems); $i++) { echo $rows['username'].', '; } And here is the code that is on every page: session_name("sid"); session_start(); include("database.php"); $user = $_SESSION['username']; mysql_query("UPDATE phpbb2_users SET lastseen=NOW() WHERE username = '{$user}'") or die(mysql_error()); What am i doing wrong?? Link to comment https://forums.phpfreaks.com/topic/62022-solved-users-online/ Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 // recommended suggestion $time = time() - 60 * 15; $members = sprintf("SELECT * FROM members WHERE last_activity <= %d", (int) $time); // polymorphism ftw? // $members = mysql_query($members); $result = mysql_query($members); $i = 0; if (mysql_num_rows($result) > 0) { while (false != ($row = mysql_fetch_assoc($result)) { echo($row['username']); ++$i; } printf('There are <b>%d</b> users online.', (int) $i); } session_name("sid"); session_start(); include("database.php"); $user = $_SESSION['username']; // UPDATE phpbb2_users SET lastseen=NOW() WHERE username = '{$user}' // lastseen? // SELECT * FROM members WHERE last_activity <= $time // last_activity? // using last_activity don't know which one is correct $q = "UPDATE phpbb2_users SET last_activity=NOW() WHERE username = '%s'" mysql_query(sprintf($q, $user)) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/62022-solved-users-online/#findComment-308836 Share on other sites More sharing options...
jemgames Posted July 30, 2007 Author Share Posted July 30, 2007 Thank you very very very much. Link to comment https://forums.phpfreaks.com/topic/62022-solved-users-online/#findComment-310799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.