PDA

View Full Version : usergroup name?


TECK
04-04-2002, 12:50 AM
i try to call the usergroup name in showthread.php with this:$usergroups=$DB_site->query("SELECT usergroup.title FROM usergroup");
while ($usergroup=$DB_site->fetch_array($usergroups)) {
$grouptitle=$usergroup['title'];
}it will not work. any ideas why?
i want to be able to call the usergroup name associated with the user, in postbit template.
thanks for taking the time to answer.

Admin
04-04-2002, 04:56 AM
To get a user's usergroup's name, you need to use this:
$getgrouptitle = $DB_site->query_first("SELECT title FROM usergroup WHERE usergroupid=$userinfo[usergroupid]");
$grouptitle = $getgrouptitle['title'];
($userinfo is the info of that user)

TECK
04-04-2002, 05:57 AM
:(Database error in vBulletin 2.2.4:

Invalid SQL: SELECT title FROM usergroup WHERE usergroupid=
mysql error: You have an error in your SQL syntax near '' at line 1

mysql error number: 1064

Script: http://localhost/forum/forum/showthread.php?threadid=7
Referer: http://localhost/forum/forumdisplay.php?forumid=2i placed the bits (in showthread.php), above:if (!$getperms['cangetattachment']) {
$viewattachedimages=0;
}i also tried to add it in functions.php, in Start buildpostbit function... same thing. any idea why is doing this?
btw, this is the answer neo gave me in msn:ohh well.. you can query Chen about the error, I am sure he can pull roses out of his mouth along with the answer :)

Neo
04-04-2002, 06:08 AM
Chen I get this error when i use the code you posted

Fatal error: Call to a member function on a non-object in c:\program files\apache group\apache\htdocs\forum\admin\functions.php on line 71

I put the code in the build postbit area. and I use 2.2.5

Admin
04-04-2002, 06:11 AM
Because $DB_site isn't avaiable in that function, and you shouldn't do that because it will add a query for every post in showthread.php.

TECK
04-04-2002, 06:21 AM
so how do i do it chen?
can i add a $DB_site to the global, in that function?

what do you recommend? in order to get the groupname in postbit?

Admin
04-04-2002, 06:30 AM
Do a query in showthread.php that caches usergroup titles in an array (id => title) then use that in getpostbit().

Zzed
04-05-2002, 01:54 AM
Ok, If I understand this correctly, you want to display the group name of the user along with is other info.

This is the original query in showthread.php:

$posts=$DB_site->query("
SELECT
post.*,post.username AS postusername,post.ipaddress AS ip,user.*,userfield.*,".iif($forum[allowicons],'icon.title as icontitle,icon.iconpath,',\
'')."
attachment.attachmentid,attachment.filename,attach ment.visible AS attachmentvisible,attachment.counter
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM post
".iif($forum[allowicons],'LEFT JOIN icon ON icon.iconid=post.iconid','')."
LEFT JOIN user ON user.userid=post.userid
LEFT JOIN userfield ON userfield.userid=user.userid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid
LEFT JOIN customavatar ON customavatar.userid=user.userid","")."
LEFT JOIN attachment ON attachment.attachmentid=post.attachmentid
WHERE $postids
ORDER BY dateline $postorder
");


This is how you change this query to get thegroup title with it:

$posts=$DB_site->query("
SELECT
post.*,post.username AS postusername,post.ipaddress AS ip,user.*,userfield.*, usergroup.title as grouptitle,".iif($forum[allowicons],'icon.titl\
e as icontitle,icon.iconpath,','')."
attachment.attachmentid,attachment.filename,attach ment.visible AS attachmentvisible,attachment.counter
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM post
".iif($forum[allowicons],'LEFT JOIN icon ON icon.iconid=post.iconid','')."
LEFT JOIN user ON user.userid=post.userid
LEFT JOIN userfield ON userfield.userid=user.userid
LEFT JOIN usergroup ON user.usergroupid=usergroup.usergroupid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid
LEFT JOIN customavatar ON customavatar.userid=user.userid","")."
LEFT JOIN attachment ON attachment.attachmentid=post.attachmentid
WHERE $postids
ORDER BY dateline $postorder
");

So in your template you can access the group title via $post[grouptitle].

I added the following text to the query: usergroup.title as grouptitle and LEFT JOIN usergroup ON user.usergroupid=usergroup.usergroupid

I tried it and I was able to show the group title along with the user info. ;)

Hope this helps. :)

TECK
04-05-2002, 01:49 PM
thanks alot... :)