vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   usergroup name? (https://vborg.vbsupport.ru/showthread.php?t=36962)

TECK 04-04-2002 12:50 AM

usergroup name?
 
i try to call the usergroup name in showthread.php with this:
PHP Code:

$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:
Code:

$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

:(
Code:

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=2

i placed the bits (in showthread.php), above:
PHP Code:

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:
Quote:

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:
PHP Code:

$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,attachment.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:
PHP Code:

$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,attachment.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... :)


All times are GMT. The time now is 12:09 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.01149 seconds
  • Memory Usage 1,750KB
  • 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
  • (2)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete