MyBB Community Forums

Full Version: team forums.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm writing plugins for team members who are online. Unfortunately, something did not go out, only shows ELSE. See for yourself.

	$query = $db->query("
		SELECT s.sid, s.ip, s.uid, s.time, u.username, u.avatar, u.usergroup, u.displaygroup
		FROM ".TABLE_PREFIX."sessions s
		LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)		
		ORDER BY u.username ASC, s.time DESC
	");
		while($user = $db->fetch_array($query))
	{
	if($mybb->settings['onlinestaff_gid'] == NULL)
{
    $onlinestaff = $user['username'];
}
else {
    $onlinestaff = 'None';
}	
	}

+ option.
$settings1 = array(
		"sid" => "NULL",
		"name" => "onlinestaff_gid",
		"title" => "Groups view",
		"description" => "Writting ID.",
		"optionscode" => "text",
		"value" => "4",
		"disporder" => ++$disporder,
		"gid" => $gid,
		);
	$db->insert_query("settings", $settings1);
.
What is wrong?
Your code absolutely do nothing. At first, you're missing WHERE statement in your query.
Do not count on cash (because I know that probably does not want anyone to write) so although write in points what I miss, what and where to add their function). But anyway the reputation you deserve.
What are you trying to achieve? Your code makes no sense.

Should be something like this, if your IDs are comma separated:
if($mybb->settings['onlinestaff_gid']) {

     $ids = " IN (". $mybb->settings['onlinestaff_gid']. ")";

     $query = $db->query("
        SELECT s.sid, s.ip, s.uid, s.time, u.username, u.avatar, u.usergroup, u.displaygroup
        FROM ".TABLE_PREFIX."sessions s
        LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
        WHERE u.usergroup $ids
        ORDER BY u.username ASC, s.time DESC
    ");

    if(!$db->num_rows($query))
    {
        //evaluate template with no rows
    } else {
        while($user = $db->fetch_array($query))
        {
              $onlinestaff = $user['username'];
              //evaluate single row template here and concatenate it
        } 
        //evaluate all rows template
    }
}

Wrote it quickly so there may be syntax mistakes.
Thank you very much, Destroy666. That's what I meant. In further parts of the plugin itself already helped. +. Smile