vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Querying Usergroups Then Array Help? (https://vborg.vbsupport.ru/showthread.php?t=210602)

paul41598 04-07-2009 09:23 PM

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?
}


Dismounted 04-08-2009 06:22 AM

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



paul41598 04-08-2009 09:23 AM

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

Dismounted 04-08-2009 09:29 AM

PHP Code:

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

print_r($usergroupdata); 


paul41598 04-08-2009 11:03 AM

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.

Dismounted 04-08-2009 11:06 AM

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.

paul41598 04-08-2009 11:13 AM

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!

Dismounted 04-09-2009 04:13 AM

Quote:

Originally Posted by paul41598 (Post 1786480)
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.

paul41598 04-09-2009 09:20 AM

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.

Dismounted 04-09-2009 11:50 AM

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


All times are GMT. The time now is 04:02 PM.

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.01115 seconds
  • Memory Usage 1,748KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete