Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Prev Previous Post   Next Post Next
  #6  
Old 02-25-2004, 07:23 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

query_first will only give you the first result row.

If this is what you want you could use
[sql]
select count(*) from user where userclassid=$groupinfo[userclassid]
[/sql]

But I wouldn't do this, as it would cause one additional query for each class.
With the query I posted before you can retrieve the information you want (how many users are in each class) with one query.

Therefore you should use smth. like this:
PHP Code:
$classes $DB_Site->query("SELECT userclassid, COUNT(userclassid) AS total FROM " TABLE_PREFIX "user BROUP BY userclassid");
while (
$class $DB_Site->fetch_array($classes))
  echo 
"There are $class[total] members in class id $class[userclassid]"
Btw: I think your whole code needs some major rework as it seems like you are executing 5 additional queries per user (!).

PHP Code:
$getuserstatus=$DB_site->query_first("SELECT title FROM useractive WHERE useractiveid=$user[activestatus]");
$getuserrace=$DB_site->query_first("SELECT title FROM userrace WHERE userraceid=$user[userraceid]");
$getusergroup=$DB_site->query_first("SELECT title FROM usergroup WHERE usergroupid=$user[usergroupid]");
$getuserrank=$DB_site->query_first("SELECT title FROM userrank WHERE userrankid=$user[userrankid]");
$getusergender=$DB_site->query_first("SELECT title FROM usergender WHERE usergenderid=$user[usergenderid]"); 
I think this is not necessary. You can have all those fields in the first query and thus being returned in array $user:

PHP Code:
$users $DB_site->query("SELECT $magelofieldselect $surnamefieldselect user.username, user.userrankid, user.activestatus, userclass.title, user.userraceid, user.userid, user.usergenderid, user.userclassid, user.usergroupid,
                          useractive.title AS userstatus, userrace.title AS userrace, userrank.title AS userrank, usergender.title AS usergender, usergroup.title AS usergroup
                          FROM " 
TABLE_PREFIX "user AS user
                          LEFT JOIN " 
TABLE_PREFIX "useractive AS useractive ON (useractive.ueractiveid = user.activestatus)
                          LEFT JOIN " 
TABLE_PREFIX "userrace AS userrace ON (userrace.userraceid = user.userraceid)
                          LEFT JOIN " 
TABLE_PREFIX "userrank AS userrake ON (userrank.userrankid = user.userrankid)
                          LEFT JOIN " 
TABLE_PREFIX "usergender AS usergender ON (usergender.usergenderid = user.usergenderid)
                          LEFT JOIN " 
TABLE_PREFIX "userclass AS userclass ON (userclass.userclassid = user.userclassid)
                          LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield ON (userfield.userid = user.userid)
                          LEFT JOIN " 
TABLE_PREFIX "usergroup AS usergroup ON (usergroup.usergroupid = user.usergroupid)
                          WHERE usergroup.rollcall = 1 AND user.userclassid != 0 ORDER BY user.userclassid, user.username ASC
                         "
); 
Reply With Quote
 

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 08:47 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.05706 seconds
  • Memory Usage 2,504KB
  • Queries Executed 12 (?)
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
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • 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_threaded
  • showthread_threaded_construct_link
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete