News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Very small db_query code to smcFunc

Started by shumilica, December 09, 2009, 07:35:08 PM

Previous topic - Next topic

shumilica

So, in Load.php is this one:
Code (Load.php) Select

$groups = $profile['additional_groups'];

// additional groups modification
if (!empty($groups))
{
$result = $smcFunc['db_query']('', '
SELECT group_name
FROM {db_prefix}membergroups
WHERE id_group IN ({array_string:groups})',
array(
'groups' => explode(', ', $groups),
)
);

while ($row = mysql_fetch_assoc($result))
$memberContext[$user]['additional_groups']['name'][] = $row['group_name'];
mysql_free_result($result);
}


And in display.template.php is now like this:


      if (!empty($message['member']['additional_groups']))
      echo implode('<br />', $message['member']['additional_groups']['name']), '<br />';


It's now working without the 2 ( i forgot about the $groups = $profile['additional_groups']; ), but is STILL showing only the first additional group...
Today, if you're not confused it means you're not thinking clear!

Arantor

And how many should there be (excluding primary group and post count group) ?

shumilica

all the additional groups they are in (excluding the primary group, and the post count group, wich are shown perfectly). If they have 2-3-4-5 additional groups that should be shown. In this way it only shows the first additional group found (it seems to be in alfabetical order :-? don't know for sure)
Today, if you're not confused it means you're not thinking clear!

Arantor


shumilica

Today, if you're not confused it means you're not thinking clear!

Arantor

Please show me an example of a user's profile and a thread they posted in, so I can take a look.

shumilica

Ok, but my bord is not in english (plus the link is to a test forum):
http://fcrp.ro/forumdetest/index.php?topic=10072.msg112077#msg112077 (username Adeela is part of at least 3 additional groups: 'tip:universitar zi', 'anul ii', 'grupa 1', 'grupa 2' etc.) but in posts it only show the 'tip:universitar zi', and it shows it first because when i created the group i've puted some spaces in the beggining so that it will show up above the groups wich started with 'a' (i told you this to explain why i said earlier in the topic that it sorts alfabetical, and only the first alfabetical addtional group is shown).
Today, if you're not confused it means you're not thinking clear!

Arantor

So what primary group does that user have, then? (That's why I wanted to see profile too)

shumilica

That example hadn't any primary membgroup, if you look again, i've put the username to a primary membergroup (Copil Inalt). Still no show (i checked with other examples).
Today, if you're not confused it means you're not thinking clear!

Arantor

It might help if you used the entire code segment I posted. mysql_fetch_assoc should not be used in 2.0 by mods.

shumilica

wow, i didn't even notice that you've changed that code too. I changed it now, but still, the same...
Today, if you're not confused it means you're not thinking clear!

Arantor

The only reason I think of is that the [] is missing in the declaration.

shumilica

Today, if you're not confused it means you're not thinking clear!

Arantor

$memberContext[$user]['additional_groups']['name'][] = $row['group_name'];

They're there in that code excerpt.

shumilica

they are in my load.php too...
So, i think this solution just doesn't work for smf2... :(
Today, if you're not confused it means you're not thinking clear!

shumilica

Hmmm, if this second solution doesn't work, the first one, that prooved working in the profile.template, do you know how to make it work in the display.template too?


// Begin modification - Additional membergroups on profile
$x = 1;
// Loop through each additional group
foreach ($message['member']['additional_groups2'] as $additional_group)
{
// Add one to our counter
$x++;
// Output this membergroup
echo '
<li class="membergroup">', $additional_group, '</li>';
}
// End modification
Today, if you're not confused it means you're not thinking clear!

Arantor

Well, assuming Display.php loads it in to $message['member']['additional_groups'] as before...


// Begin modification - Additional membergroups on profile
$x = 1;
// Loop through each additional group
foreach ($message['member']['additional_groups'] as $additional_group)
{
// Add one to our counter
$x++;
// Output this membergroup
echo '
', $additional_group, '<br />';
}
// End modification

Advertisement: