Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Klajdi on January 22, 2017, 12:21:57 PM

Title: Get member's group data in membergroup table from database
Post by: Klajdi on January 22, 2017, 12:21:57 PM
Lets say membergroup A has subid set to 0 and membergroup B has subid set to 1, how do I get the value corresponding to each member?
(member Tom who is a member of group A shows value 0 and John who is a member of group B shows value 1)
Probably the same way as $message['member']['group']
(subid is a custom row which is set in membergroup edit panel)

  $query = $smcFunc['db_query']('', '
    SELECT subid
    FROM {db_prefix}membergroups
    WHERE id_group = {int:current_group}',
array(
'member' => (int) $context['user']['id'],
'current_group' => $message['member']['id'],
)
);

$row = $smcFunc['db_fetch_assoc']($query);
  $smcFunc['db_free_result']($query);

echo $row['subid']

Is the above code correct?
Title: Re: Get member's group data in membergroup table from database
Post by: vbgamer45 on January 29, 2017, 10:51:52 AM
The query looks ok but tt depends where it is called at
But does it work for you?
Title: Re: Get member's group data in membergroup table from database
Post by: Klajdi on January 29, 2017, 12:33:12 PM
Quote from: vbgamer45 on January 29, 2017, 10:51:52 AM
The query looks ok but tt depends where it is called at
But does it work for you?
Yes and no, apparently It works only in Display.template.php as I have to define many things to use it somewhere else.
Following this thread http://www.simplemachines.org/community/index.php?topic=551663.0
I managed to find a workaround, so it is now defined as $memberContext[$message['id_member']]['subid_show']
and works on Display.php (and I believe wherever the $memberContext is defined),
Now:
Quote from: Klajdi on January 28, 2017, 08:09:16 AM
Quote from: nend on January 28, 2017, 12:05:32 AM
It is actually defined in the while statement in the display template. This data doesn't have a long TTL as it is done this way for memory reasons.

What happens is the query is created in the display sources and when the template is called it loads the defined function and the query is executed.

I believe if memory serves me right, this is the only area in SMF the query is actually made while in a template. May be the reason your having trouble with it.
I managed to add it in the "$memberContext[$message['id_member']]['subid_show']", I want to know how to use it Sub-Simplecolorizer.php
Title: Re: Get member's group data in membergroup table from database
Post by: Klajdi on January 29, 2017, 01:08:04 PM
Anyhow, that is another topic, Id like to stop this topic here.
This works on Display.template.php
$query = $smcFunc['db_query']('', '
SELECT subid_show
FROM {db_prefix}membergroups
WHERE group_name = {string:current_groupname}',
array(
'member' => (int) $context['user']['id'],
'current_groupname' => $message['member']['group'],
)
);

$row = $smcFunc['db_fetch_assoc']($query);

$smcFunc['db_free_result']($query);
 
echo $row['subid_show'];

Thanks for your help and time vbgamer45.