How to Fetch DB Info

  • Hello me again, hopefully this time I can get some kind of feedback :P

    I want to fetch some info from the database so I can display a simple image for a userGroup.

    The table is wcf1_user_to_group and im trying to fetch the groupID.

    Any idea what code I can use to fetch that info?

    Thank you! :thumbsup:

  • Hi,

    because users are always in at least 2 groups you will receive several group IDs as result.

    Inside a WCF script you access the group IDs by calling the method getGroupIDs on an user object. So the userIDs of the current user could be acces like this:

  • Would this get the information from the user_to_group table?

    If so, you just saved me so many hours of work! xD

  • Yes :D The small code bit I've posted above, returns all group IDs of the current user (the script executing user).

  • Perfect! Now lets say....I want only two out of all the groups to only show up.

    Like groupID 8 & 9.
    Can I make a {if} {/if} to only allow those groups from showing?


  • Hmm inside template code it would be different. Do you want these functions inside the template or a PHP script, because this is a big difference. In a PHP script it could look like this:

    $groupIDs = array(8,9);
    $userGroupIDs = WCF::getUser()->getGroupIDs();
    if(in_array($groupIDs, $userGroupIDs) {
    //do something
    else {
    //do nothing

    Of course you can leave out the else-clause. It's just for demonstration ;) Im not absolutely sure atm if the getGroupIDs function returns the groupIDs as array or as concatenated string, but the transformation between those two is easy.

  • PHP or Template, but template would be an easier to customize for the board.

    Im just getting used to this system of wBB3. I mean, its a fantastic system, but a bit difficult for a newbie like myself.