Jump to content

[SOLVED] Users Online


jemgames

Recommended Posts

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


// 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.