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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.