The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
List members of additional usergroup
I am attempting to have a page which lists all users in a usergroup (additional usergrou). I realize I am able to do so via ACP, but I wish to have this list accessible to moderators.
I have the following code below, but am not sure where lies the error.. any help is appreciated. Code:
<?php $groupid = 43; $users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user WHERE usergroupid = $groupid"); $str = ''; $sep = ''; while ($user = $vbulletin->db->fetch_array($users)) { $str .= $sep . $user['username']; $sep = ', '; } // $str is comma separated list of users in $groupid $vbulletin->db->free_result($users); echo "Market Banned: $str"; ?> |
#2
|
|||
|
|||
What happens, do you just get no user names? Is 43 a secondary user group, by any chance? If so I think you'd want
Code:
WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids) |
#3
|
|||
|
|||
Quote:
Fatal error: Call to a member function query_read() on a non-object in mban.php on line 3 Will report back with your edit. Edit: Code:
<?php $groupid = 43; $users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids); $str = ''; $sep = ''; while ($user = $vbulletin->db->fetch_array($users)) { $str .= $sep . $user['username']; $sep = ', '; } // $str is comma separated list of users in $groupid $vbulletin->db->free_result($users); echo "Market Banned: $str"; ?> |
#4
|
|||
|
|||
The error you were getting is because the db object isn't defined, which usually is because $vbulletin isn't in scope. The new error is because you're missing a close quote on the query string. Try this:
PHP Code:
That assumes that what you posted is only part of a page (like it's included or it's plugin code or something). If you're trying to make a stand-alone page then you need to inlucde global.php. (If you are trying to make a page you might want to look at this: https://vborg.vbsupport.ru/showthread.php?t=228112). |
#5
|
|||
|
|||
Quote:
Thanks |
#6
|
|||
|
|||
You should be able to take this part of the code:
PHP Code:
and put it where the tutorial says "// ###### YOUR CUSTOM CODE GOES HERE #####". Then instead of using echo, you'd probably want to register $str as a variable in your template like: HTML Code:
$templater->register('str', $str); |
#7
|
|||
|
|||
Quote:
marketbanned.php contents vvv Code:
<?php // ####################### SET PHP ENVIRONMENT ########################### error_reporting(E_ALL & ~E_NOTICE); // #################### DEFINE IMPORTANT CONSTANTS ####################### define('THIS_SCRIPT', 'mban'); define('CSRF_PROTECTION', true); // change this depending on your filename // ################### PRE-CACHE TEMPLATES AND DATA ###################### // get special phrase groups $phrasegroups = array(); // get special data templates from the datastore $specialtemplates = array(); // pre-cache templates used by all actions $globaltemplates = array('mbanned', ); // pre-cache templates used by specific actions $actiontemplates = array(); // ######################### REQUIRE BACK-END ############################ // if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line // chdir ('/path/to/your/forums'); require_once('./global.php'); // ####################################################################### // ######################## START MAIN SCRIPT ############################ // ####################################################################### $navbits = construct_navbits(array('' => 'Market Banned Users')); $navbar = render_navbar_template($navbits); // ###### YOUR CUSTOM CODE GOES HERE ##### $pagetitle = 'Market Banned Users'; $groupid = 43; $users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids)"; $str = ''; $sep = ''; while ($user = $vbulletin->db->fetch_array($users)) { $str .= $sep . $user['username']; $sep = ', '; } // $str is comma separated list of users in $groupid $vbulletin->db->free_result($users); $templater->register('str', $str); // ###### NOW YOUR TEMPLATE IS BEING RENDERED ###### $templater = vB_Template::create('mbanned'); $templater->register_page_templates(); $templater->register('navbar', $navbar); $templater->register('pagetitle', $pagetitle); print_output($templater->render()); ?> Code:
{vb:stylevar htmldoctype} <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html"> <head> <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title> {vb:raw headinclude} {vb:raw headinclude_bottom} </head> <body> {vb:raw header} {vb:raw navbar} <div id="pagetitle"> <h1>{vb:raw pagetitle}</h1> </div> <h2 class="blockhead">Title</h2> <div class="blockbody"> <div class="blockrow"> {vb:raw str}. </div> </div> {vb:raw footer} </body> </html> |
#8
|
|||
|
|||
My fault, there's a missing ')' on the query line so it should be
PHP Code:
also, you want to move your $templater->register('str', $str) down to where the other $templater->register() lines are. |
#9
|
|||
|
|||
Quote:
Lastly, instead of seperating these users with commas , how would I go about doing so with line breaks rather than ' , ' ? I also attempted to add a conditional to the template to only display the str output to certain usergroups, but it was unsuccessful. Would the condition need to be done in the PHP file rather than in the template? Thanks again for all your help |
#10
|
||||
|
||||
Quote:
HTML Code:
<br />
--------------- Added [DATE]1311128579[/DATE] at [TIME]1311128579[/TIME] --------------- so just change PHP Code:
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|