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:


    PHP
    1. WCF::getUser()->getGroupIDs();
  • 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?


    :thumbsup:

  • 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:


    PHP
    1. $groupIDs = array(8,9);
    2. $userGroupIDs = WCF::getUser()->getGroupIDs();
    3. if(in_array($groupIDs, $userGroupIDs) {
    4. //do something
    5. }
    6. else {
    7. //do nothing
    8. }



    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.