Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2011, 09:24 PM
Spyike Spyike is offline
 
Join Date: Nov 2010
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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";  
?>
Reply With Quote
  #2  
Old 07-19-2011, 09:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #3  
Old 07-19-2011, 10:09 PM
Spyike Spyike is offline
 
Join Date: Nov 2010
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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)
It is an additional usergroup, the error I receive is:
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";  
?>
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in mban.php on line 9
Reply With Quote
  #4  
Old 07-19-2011, 10:19 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
<?php 
global $vbulletin;

$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";  
?>

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).
Reply With Quote
  #5  
Old 07-19-2011, 10:52 PM
Spyike Spyike is offline
 
Join Date: Nov 2010
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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:
<?php 
global $vbulletin;

$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";  
?>

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).
I am just looking to have a page that displays those users so moderators can have it readily available if needed. I have created the template and page as shown in the tutorial you linked; however, I am not sure where to place the original code snipped you posted above as I cannot put it in the template itself. Would I need to create a plugin and include that in the template? If so, what hook do I need to use and what would I do?
Thanks
Reply With Quote
  #6  
Old 07-19-2011, 11:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should be able to take this part of the code:

PHP Code:
$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); 

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);
(you can see where these go in the example code), and then use it in a tag in the template like {vb:raw str}.
Reply With Quote
  #7  
Old 07-19-2011, 11:26 PM
Spyike Spyike is offline
 
Join Date: Nov 2010
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You should be able to take this part of the code:

PHP Code:
$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); 

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);
(you can see where these go in the example code), and then use it in a tag in the template like {vb:raw str}.
Now getting a syntax error :/

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());

?>
mbanned template contents vv
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>
Reply With Quote
  #8  
Old 07-19-2011, 11:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My fault, there's a missing ')' on the query line so it should be

PHP Code:
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user  
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"); 

also, you want to move your $templater->register('str', $str) down to where the other $templater->register() lines are.
Reply With Quote
  #9  
Old 07-20-2011, 01:20 AM
Spyike Spyike is offline
 
Join Date: Nov 2010
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
My fault, there's a missing ')' on the query line so it should be

PHP Code:
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user  
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"); 

also, you want to move your $templater->register('str', $str) down to where the other $templater->register() lines are.
Worked fabulously! Thank you!

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
Reply With Quote
  #10  
Old 07-20-2011, 01:22 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Spyike View Post
Worked fabulously! Thank you!

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
Pretty sure using
HTML Code:
<br />
would work

--------------- Added [DATE]1311128579[/DATE] at [TIME]1311128579[/TIME] ---------------

so just change
PHP Code:
$sep ', '
to
PHP Code:
$sep '<br />'
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:45 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10019 seconds
  • Memory Usage 2,309KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (3)bbcode_html
  • (8)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete