Jump to content

Variable not updating


NICON
Go to solution Solved by requinix,

Recommended Posts

function callback($buffer) {
    global $user_class, $db, $m;
    if (!$m->get('membersonline.' . $user_class->gang)) {
        $db->query("SELECT COUNT(id) FROM grpgusers WHERE gang = ? AND lastactive >= ?");
        $db->execute(array(
            $user_class->gang, 
            time() - 900
        ));
        $membersonline = $db->fetch_single();
        $m->set('membersonline.' . $user_class->gang, $membersonline);
    } else
        $membersonline = $m->get('membersonline.' . $user_class->gang);
   
   $buffer = str_replace("<!_-monline-_!>", $membersonline ? "<font color='yellow'><strong>" . prettynum($membersonline) . "</strong></font>" : 0, $buffer);
   return $buffer;
}
ob_start("callback");

<a href="test.php">Test Line [<!_-monline-_!>]</a>

My problem is quite simple but yet I cant figure it out. I want $membersonline to update as people go inactive using the existing format for similar data. Above is just that but as the number increases it just holds to the highest number and never drops lower. i.e. if the value shown is 3 and I check who is online and its 1 why is 3 still showing? Thanks in advance.

Edited by NICON
Link to comment
Share on other sites

That was the issue. I had stored a permanent variable in the cache and of coarse it would not update. I fixed it though with this:

if (!$m->get('membersonline.' . $user_class->gang)) {
        $db->query("SELECT COUNT(id) FROM grpgusers WHERE gang = ? AND lastactive >= ?");
		$db->execute(array(
			$user_class->gang, 
			time() - 900
		));
        $membersonline = $db->fetch_single();
        $m->set('membersonline.' . $user_class->gang, $membersonline, 1);
    } else
        $membersonline = $m->get('membersonline.' . $user_class->gang);

of coarse I enabled this after destroying the old variable. Thanks for your reply!

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.