The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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? } |
#2
|
||||
|
||||
You don't need to "re-fetch" the usergroup ids, it's already there...
PHP Code:
|
#3
|
||||
|
||||
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 |
#4
|
||||
|
||||
PHP Code:
|
#5
|
||||
|
||||
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.
|
#6
|
||||
|
||||
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.
|
#7
|
||||
|
||||
Well I tried this:
outside the while loop Code:
foreach ($usergroupdata AS $test) { eval('$der .= "' . fetch_template('jon') . '";'); } 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') . '";'); } 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']; |
#8
|
||||
|
||||
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.
|
#9
|
||||
|
||||
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. |
#10
|
||||
|
||||
Make sure you have changed the variables in the template... (Also post the code you are using now.)
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|