Customizing SMF > SMF Coding Discussion
Pulling Additional MemberGroups
Melissa524:
I have a code that is used to pull up Primary Groups only. I want to change it to pull out Additional/Secondary Member Groups only instead (or additional). Can anyone help me?
--- Code: ---global $user_profile, $smcFunc, $scripturl;
//This is the SQL query to pull the data; the id_group NOT IN should include the group id's you don't want to include, like "no group" or "unapproved" or whathaveyou. I don't include accounts in the players group or admins either. This is primary group.
$request = $smcFunc['db_query']('' ,'
SELECT m.real_name, m.id_group, m.id_member, m.usertitle, m.avatar, g.group_name, g.online_color
FROM {db_prefix}membergroups AS g
LEFT JOIN {db_prefix}members AS m ON g.id_group = m.id_group
WHERE m.id_group NOT IN (0,1,2,3,9,100) ORDER BY g.group_name, m.real_name',
array(
)
);
// This is for text that prints above the list. Make sure you escape out single tickmarks (like apostrophes) if you'll be using any within the echo.
if (!$request)
db_fatal_error();
$thisgroup = "";
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$usertitle = "";
// This orders the list by groups, and only prints the group name when it's time to pull up a new group in the list.
if($thisgroup != $row["group_name"]) {
echo '
<div class="page-title" style="padding: 10px; margin-top: 10px; border-bottom: 1px solid', $row["online_color"], '">
<a style="color: ', $row["online_color"], ';" href="', $scripturl, '?action=groups;sa=members;group=', $row["id_group"], '">', $row["group_name"], '</a>
</div>';
$thisgroup = $row["group_name"];
}
if ($row["usertitle"] !="") {
$usertitle= ": " . $row["usertitle"];
}
echo '
<div class="page-list">
<span class="page-indent"><a href="', $scripturl, '?action=profile;u=', $row["id_member"], '">', $row["real_name"], '</a>', $usertitle;
if ($row["personal_text"] !="") {
echo '</span><span class="page-personal">', $row["personal_text"];
}
echo '
</span>
</div>';
}
$smcFunc['db_free_result']($request);
--- End code ---
Arantor:
You actually can't do it like that for additional groups.
A member's secondary groups are stored in additional_groups in the members table. You need to pull that column, explode() it on ',' to get a list of groups, and then proceed to query to get the details for all those extra groups.
Without knowing the intent of this piece of code (i.e. where you're running it) it's hard to say what exactly is best.
Melissa524:
Hmm... Okay. I am using it in a php page on simpleportal. And I really have no idea how to do that. My friend gave me a small bit of code that is used to do something like that on her site, but it doesn't have the look I am working for. I will give you that coding just in case it helps. I tried "merging" the div set-up for this code and putting it in the secondary code, but I couldn't get it to work (I am slowly learning php on my own). I was told that the second code is a bit messy, but it does pull out the member groups.
--- Code: ---<?php
global $txt, $scripturl, $user_info;
global $context, $modSettings, $id_member;
global $board_info, $settings, $db_prefix, $smcFunc;
///////////////////////////////////////////////////////////////// Enter the desired groups
$groups_list = array(18);
/////////////////////////////////////////////////////////////////
$groups_query1 = 'mem.additional_groups IN ({array_int:groups1})';
$groups_query2 = '';
// $groups_query2 = ' OR FIND_IN_SET(' . implode(', mem.additionalGroups) OR FIND_IN_SET(', $groups_list) . ', mem.additionalGroups)';
$loaded_ids = array();
$user_profile=array();
$memberContext=array();
$profile=array();
$context['team']=array();
// Load the member's data.
$request = $smcFunc['db_query']('', '
SELECT IFNULL(lo.log_Time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.personal_text, mem.avatar, mem.id_member, mem.member_name, mem.real_name , mem.last_login, mem.website_title, mem.usertitle,
mem.website_url, mem.location, mem.posts, them.value AS teamtext, g.group_name, d.value AS cust_dragon, s.value AS cust_profil, age.value AS cust_charac
FROM {db_prefix}members AS mem
INNER JOIN {db_prefix}membergroups AS g ON (mem.id_group = g.id_group)
LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}themes AS them ON (mem.id_member = them.id_member AND them.variable = {string:theme_var} AND them.ID_THEME=1)
LEFT JOIN {db_prefix}themes AS d ON (mem.id_member = d.id_member AND d.variable = {string:d_var} AND d.ID_THEME=1)
LEFT JOIN {db_prefix}themes AS s ON (mem.id_member = s.id_member AND s.variable = {string:s_var} AND s.ID_THEME=1)
LEFT JOIN {db_prefix}themes AS age ON (mem.id_member = age.id_member AND age.variable = {string:age_var} AND age.ID_THEME=1)
WHERE (' . $groups_query1 . $groups_query2 . ')
ORDER BY mem.real_name ASC',
array(
'groups1' => $groups_list,
'theme_var' => 'cust_player',
'd_var' => 'cust_dragon',
's_var' => 'cust_profil',
'age_var' => 'cust_charac',
)
);
$new_loaded_ids = array();
while ($row = mysql_fetch_assoc($request))
{
$avatar_width = '';
$avatar_height = '';
$context['team'][] = array(
'username' => $row['member_name'],
'name' => $row['real_name'],
'groupname' => $row['group_name'],
'posts' => $row['posts'],
'usertitle' => $row['usertitle'],
'location' => $row['location'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['real_name'] . '">' . $row['real_name'] . '</a>',
'blurb' => $row['personal_text'],
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar2" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar2" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar2" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
'teamtext' => $row['teamtext'],
);
}
mysql_free_result($request);
echo '<table align="center" width="100%" cellpadding="5" cellspacing="5" style="margin-top: 10px;"><tr>';
$newrow=0;
foreach($context['team'] as $team)
{
echo '
<td valign="top" align="right" width="5%">'.$team['avatar']['image'].'</td>
<td valign="top" width="45%" style="padding: 4px;">
<h2 style="margin-top: 0; margin-bottom: 0px;">'.$team['link'].'</h2>
<h2 style="margin-top: 0; margin-bottom: 4px;">'.$team['usertitle'].'</h2>
<p align="left"><b>Player:</b> '.$team['teamtext'].'<br />
<b>Profile:</b> <a href="http://www.thepernese.com/index.php?topic='.$team['cust_profil'].'.0">Sheet</a><br />
<b>Age:</b> <script type="text/javascript">x='.$team['cust_charac'].'+1;document.write(x);</script> Turns<br />
<b>Dragon:</b> '.$team['cust_dragon'].'<br />' , '
</div></td>';
$newrow++;
if($newrow>1){
$newrow=0;
echo '</tr><tr>';
}
}
echo '</tr></table>';
?>
--- End code ---
Arantor:
Hm, I'm not exactly sure what you plan to do with the extra membergroups for the users, that's part of the problem :/
Melissa524:
The first code does this (screen shot of the code in action). I want to do the same thing here but instead it would pull up secondary groups instead of primary ones and then list all the characters in that group. Does that make any sense?
Navigation
[0] Message Index
[#] Next page
Go to full version