phpBB intergration with phpBB Fetch All

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

phpBB intergration with phpBB Fetch All

Post by therat »

I am going to use phpBB Fetch All to integrate the forum with a site. I am trying to show a list of users currently online using one of the built in functions. It does not display the online users correctly, I have posted at their forums but got no response. I would also like to trun it into a function to reuse in various places.
The code they use as an example is

Code: Select all

<!-- ONLINE USERS -->
<?php if (isset($online)) { ?>
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline">
  <tr>
    <td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Who_is_Online']; ?></span></td>
  </tr>
  <tr>
    <td class="row1" align="left" width="100%">
      <span class="gensmall">
<?php for ($i = 0; $i < count($online); $i++) { ?>
<a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $online[$i]['user_id']); ?>">
<?php echo $online[$i]['username']; ?></a><?php if ($i < count($online) - 1) { ?>, <?php } ?>
<?php } ?>
<?php if ($i) { ?>, <?php } ?>
<?php if ($stats['user_online'] - $i == 1) { printf($lang['Guest_user_total'], $stats['user_online'] - $i); }
 else { printf($lang['Guest_users_total'], $stats['user_online'] - $i); } ?>
      </span>
    </td>
  </tr>
</table>
<br />
<?php } ?>
<!-- ONLINE USERS -->
and this is the function that pulls the info from the db

Code: Select all

function phpbb_fetch_online_users($group_id = null)
{
	global $CFG;

	//
	// sanity check
	//

	if ($group_id and !intval($group_id))
	{
		phpbb_raise_error('Group ID must be a numeric value.',
			__FILE__, __LINE__);
	}

	//
	// build the sql string
	//

	$sql = 'SELECT u.user_id, u.username, u.user_allow_viewonline,
			u.user_level, s.session_logged_in, s.session_time';

	if ($group_id)
	{
		$sql .= ', g.*, ug.*';
	}

	$sql .= '
		FROM
		' . USERS_TABLE    . ' AS u,
		' . SESSIONS_TABLE . ' AS s';

	if ($group_id)
	{
		$sql .= ',
			' . GROUPS_TABLE     . ' AS g,
			' . USER_GROUP_TABLE . ' AS ug';
	}

	$sql .= '
		WHERE u.user_id = s.session_user_id
		AND s.session_time >= '
		. (time() - $CFG['users_session_time']);

	if ($group_id)
	{
		$sql .= '
			AND g.group_id = '  . $group_id . '
			AND ug.group_id = ' . $group_id . '
			AND u.user_id = ug.user_id
			AND ug.user_pending = 0';
	}

	$sql .= '
		ORDER BY u.username ASC';

	$result = phpbb_fetch_rows($sql);

	//
	// delete hidden and guest users
	//

	$cleanup = array();
	$prev_user = 0;

	for ($i = 0; $i < count($result); $i++)
	{
		if ($result[$i]['session_logged_in'])
		{
			$user_id = $result[$i]['user_id'];
			if ($user_id != $prev_user)
			{
				if ($result[$i]['user_allow_viewonline'])
				{
					$cleanup[] = $result[$i];
				}
				$prev_user = $user_id;
			}
		}
	}

	return $cleanup;
} // end func phpbb_fetch_online_users
When a single user is logged in it works correctly, when I log in again, different user & browser, the stats are wrong. Has anyone used this before or know of a working example?
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

the reason you didn't get help from the other forums could be because you did not say what the problem was. Saying that the stats showed up wrong ...turn people away :!:
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Post by therat »

I did post whats wrong at the other form, just seem to have forgotten to do that here :oops:

When not logged in it should say 0 Guests or however many there are. At the moment it displays nothing at all.

When I log in it displays who I have logged in as + 1 guest ie, Test1, 1 Guest. Obviously it should say 0 Guests.

When I log in as another user with a different browser it displays Test1, 1 Guest, Test2, 0 Guests.

It is showing the names of logged in users correctly, it just appears to be the number of Guests it is having problems with.
I appreciate the help if anyone has a solution.
Post Reply