Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2009, 09:23 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Querying Usergroups Then Array Help?

I'm like really still newb when it comes to this stuff. Essentially I'm trying to pull all usergroups someone is in, primary and secondary. Then I want to display checkboxes for each group with the usergroup title next to each checkbox. So if a user is apart of 2 groups, then 2 checkboxes will appear with each usergroup name.

I'm thinking my theory is correct. I'm querying the database, then I get somewhat stumped. Won't I want to somehow put the ID's I get back in an array, and then use the array for the checkbox? Any pointers from here on out?



Code:
$users = $vbulletin->db->query_read("
SELECT user.userid, user.usergroupid, user.membergroupids, usergroup.usergroupid, usergroup.title 
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON(usergroup.usergroupid = user.usergroupid)
WHERE user.userid = ".$vbulletin->userinfo['userid']."
");

while ($user1 = $vbulletin->db->fetch_array($users))
{

//checkbox stuff here
like $variable = '<input type="checkbox"> blah blah?
}
Reply With Quote
  #2  
Old 04-08-2009, 06:22 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need to "re-fetch" the usergroup ids, it's already there...
PHP Code:
$usergroupids $vbulletin->userinfo['usergroupid'];

if (!empty(
$vbulletin->userinfo['membergroupids']))
{
    
$usergroupids .= ',' $vbulletin->userinfo['membergroupids'];
}

$usergroups $vbulletin->db->query_read("
    SELECT *
    FROM " 
TABLE_PREFIX "usergroup
    WHERE usergroupid IN (
$usergroupids)
"
);

while (
$usergroup $vbulletin->db->fetch_array($usergroups))
{
    
// some stuff

Reply With Quote
  #3  
Old 04-08-2009, 09:23 AM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ahh, that makes sense. So I can echo back $usergroupids, and I get all of the id's but what about the title of the usergroup? IF in the while loop I do a $title = $usergroup['title']; and put that $title variable in the newthread template, I only get 1 title to show up, even tho a user is apart of 3 groups. I was looking to display all the usergroup titles they are apart of.

Actually I need a checkbox associated to each user title. Would I need a for each loop? Thanks again dismounted
Reply With Quote
  #4  
Old 04-08-2009, 09:29 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$usergroupdata = array();
while (
$usergroup $vbulletin->db->fetch_array($usergroups))
{
    
$usergroupdata[$usergroup['usergroupid']] = $usergroup['title'];
}

print_r($usergroupdata); 
Reply With Quote
  #5  
Old 04-08-2009, 11:03 AM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I see, so that puts their usergroups in an array. Now I'd have to break out the array from there it sounds like. Thanks dismounted. Feel free to PM me if you have free time.
Reply With Quote
  #6  
Old 04-08-2009, 11:06 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm just demonstrating how it could be used. You don't have to store it inside an array, and then loop that array. Just generate template data inside the loop.
Reply With Quote
  #7  
Old 04-08-2009, 11:13 AM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well I tried this:

outside the while loop

Code:
foreach ($usergroupdata AS $test) {
eval('$der .= "' . fetch_template('jon') . '";');
}
and inside that template I put the variable $test

and it prints out all the usergroup titles, so it worked! However your saying it could be done another way right? Which is best?

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

Ok got a little further but stuck again.

newthread form complete hook:

Code:
$usergroupids = $vbulletin->userinfo['usergroupid'];

if (!empty($vbulletin->userinfo['membergroupids']))
{
    $usergroupids .= ',' . $vbulletin->userinfo['membergroupids'];
}

$usergroups = $vbulletin->db->query_read("
    SELECT *
    FROM " . TABLE_PREFIX . "usergroup
    WHERE usergroupid IN ($usergroupids)
");

$usergroupdata = array();
while ($usergroup = $vbulletin->db->fetch_array($usergroups))
{
$usergroupdata[$usergroup['usergroupid']] = $usergroup['title'];
}

foreach ($usergroupdata AS $value1 => $value) {
eval('$der .= "' . fetch_template('jon') . '";');
}
Templete Jon:

Code:
<label for="usergroups">
<input type="checkbox" name="value1[]" value="$value1" id="" tabindex="1" />$value
</label>

newthread post complete hook:

Code:
$vbulletin->input->clean_array_gpc('p', array('value1' => TYPE_ARRAY));

echo $vbulletin->GPC['value1'];
Granted theres supposed to be more code in the post complete hook, but the theory at least for now is just echo back whichever checkbox was selected. However value1 isn't doing me any good!
Reply With Quote
  #8  
Old 04-09-2009, 04:13 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by paul41598 View Post
However your saying it could be done another way right? Which is best?
What you're doing is using two loops, when you can just use one. Just place the template eval() into the while loop, removing the second unnecessary foreach() loop.
Reply With Quote
  #9  
Old 04-09-2009, 09:20 AM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I'll try that....thank you dismounted

Although when I did that, now it only shows 1 usergroup, as opposed to the 3 that Im apart of. So I think that foreach loop was needed.
Reply With Quote
  #10  
Old 04-09-2009, 11:50 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Make sure you have changed the variables in the template... (Also post the code you are using now.)
Reply With Quote
Reply

Thread Tools
Display Modes

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 12:50 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08880 seconds
  • Memory Usage 2,261KB
  • 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
  • (5)bbcode_code
  • (2)bbcode_php
  • (1)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