Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2013, 04:21 PM
Sarcoth Sarcoth is offline
 
Join Date: Mar 2006
Location: Huntsville
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query and Output

My query is working the way I want it, but I'm not sure I'm displaying the output in the most efficient way. Although, it is displaying exactly the way I want.

PHP Code:
/* The usergroups that will appear on the roster */
$usergroupids $permissions['rostermembers'];                    // the string = 40,41,42,43
$displaygroups = array();
$displaygroups explode(',',$usergroupids);                    // convert to array

/* More selective on which fields to view from the user table */
$user_table "user.userid, user.usergroupid, user.membergroupids, user.username, user.joindate, user.lastactivity, user.avatarid ";

/* Create the query for viewing data */
$query "SELECT $user_table, userfield.* ";
$query .= "FROM " TABLE_PREFIX "user AS user ";
$query .= "LEFT JOIN " TABLE_PREFIX "userfield AS userfield ";
$query .= "ON user.userid = userfield.userid ";
$query .= "WHERE (user.usergroupid IN ($usergroupids) ";
$query .= "OR FIND_IN_SET(" implode(', user.membergroupids) OR FIND_IN_SET('$displaygroups) . ", user.membergroupids)) ";

/* Now let's run the query */
$result $db->query_read_slave($query);

$rowcount mysql_num_rows($result);
printf("Rows:  %d<br \>"$rowcount);

foreach(
$displaygroups AS $groupid) {
    
printf("Group:  %s<br \>"$groupid);
    while(
$roster $db->fetch_array($result)) {
        
$membergroupids explode(',',$roster['membergroupids']);
        if (
$groupid == $roster['usergroupid'] || in_array($groupid$membergroupids)) {
            
printf("Username:  %s<br \>"$roster['username']);
            
$charinfo['count']++;
        }
        unset(
$membergroupids);
    }
    
mysql_data_seek($result0);

Output
Rows: 7
Group: 40
Username: Name1
Group: 41
Group: 42
Username: Name2
Username: Name3
Username: Name4
Username: Name5
Username: Name6
Username: Name7
Group: 43

The way the output is being displayed right now, it is going through the query multiple times. The number of times is equal to how many groups there are. This won't be much of a problem if there are only 4 groups and the total number of people is low. But, I'm concerned if there are 10 groups and over 200 (or more) users. Any suggestions on a better way to display the data?

Thanks in advance for any suggestions.
Reply With Quote
Reply


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 10:56 AM.


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.18296 seconds
  • Memory Usage 2,218KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • 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