need help with friends and foes mod

PHP coding talk.

Moderator: Moderators

need help with friends and foes mod

Postby 2bit on Fri Aug 08, 2008 3:15 am

I am currently working on displaying who is online and offline among the users friends and foes. I had to combine the three arrays ($online, $foes, and $friends) I need someone to check the code so far. here is the code

friends_foes.php
Code: Select all
$sql = 'SELECT z.friend, u.username, u.username_clean
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends[] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes[] = utf8_clean_string($row['username']);
    }
}
$db->sql_freeresult($result);

if (sizeof($friends))
{
    foreach ($friends as $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
        ));
    }
}

if (sizeof($foes))
{
    foreach ($foes as $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
        ));
    }
}

// do this after you have $friends and $foes defined
$users = array_merge($friends, $foes);

$sql = 'SELECT session_user_id, MAX(session_time) AS onlinetime, MIN(session_viewonline) AS viewonline FROM ' . SESSIONS_TABLE . '
WHERE ' . $db->sql_in_set('session_user_id', $users) . '
GROUP BY session_user_id';
$result = $db->sql_query($sql);

$current_time = time();
while ($row = $db->sql_fetchrow($result))
{
if (($row['viewonline'] || $auth->acl_get('u_viewonline')) && $row['onlinetime'] > ($current_time - $config['load_online_time'] * 60))
{
$online[$row['session_user_id']] = true;
}
}
$db->sql_freeresult($result);
$sql = 'SELECT z.friend, u.username, u.username_clean, z.zebra_id
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends['zebra_id'] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes['zebra_id'] = utf8_clean_string($row['username']);
    }

//Then at the end,


    foreach ($friends as $id => $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }
foreach ($foes as $id => $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }

Thanks a bunch!
2bit
Registered User
Registered User
 
Posts: 1
Joined: Fri Aug 08, 2008 12:04 am

Return to PHP Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron