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

Reply
 
Thread Tools Display Modes
  #11  
Old 01-12-2005, 02:06 PM
GrBear GrBear is offline
 
Join Date: Aug 2004
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's the solution I can up with that works.

PHP Code:
$array = array();
$dbquery $DB_site->query("SELECT field5 FROM " TABLE_PREFIX "userfield"); 

while (
$queryrow $DB_site->fetch_array($dbquery))
    {
        
$array[$queryrow['field5']]++;
    }
reset($array);
while (list(
$key$val) = each($array))
    {
                    
$f5stat .= $val " = " $key;
    } 
Thanks for all the help folks, it was appreciated!
Reply With Quote
  #12  
Old 01-12-2005, 06:36 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Keep in mind, you'll be running through a table that can be a couple of thousand rows large, depending on the number of members on your board..

You should use the solution provided by MarcoH64
Reply With Quote
  #13  
Old 01-12-2005, 09:26 PM
GrBear GrBear is offline
 
Join Date: Aug 2004
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good point. It would make sense that it would be quicker for the DB engine to tabulate the totals rather than have PHP parse each row individually from the DB.

I'll give it a shot.

Thanks!
Reply With Quote
  #14  
Old 01-12-2005, 11:20 PM
GrBear GrBear is offline
 
Join Date: Aug 2004
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I had to modify my the code of course for the new SELECT, and by tweaking the SQL statement further, I was able offload the sorting to the DB since I wanted the results displayed by the highest total to the lowest.

PHP Code:
$dbquery $DB_site->query("SELECT field5, COUNT(field5) AS total FROM " TABLE_PREFIX "userfield GROUP BY field5 ORDER BY total DESC"); 

while (
$queryrow $DB_site->fetch_array($dbquery))
    {
        
$f5stat .= $queryrow['total'] . " " $queryrow['field5'];
    } 
There was a bit of extra html layout code in there as well, but for easier readability I left it out.

Much simpler execution to the problem. Again, many thanks! :up:
Reply With Quote
  #15  
Old 01-13-2005, 03:39 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sometimes the solution to something that seems complicated can be real simple.
Reply With Quote
  #16  
Old 02-06-2005, 04:53 AM
pshadow pshadow is offline
 
Join Date: Feb 2002
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this was great. I tried to do the same thing and it works perfect. thanks.

I'm wondering how to make 2 edits though:
1. exclude counting and displaying the empty fields. currently shows 500 blank.
2. not really related but, it displays whats in the field5 fine, how do I get the original field number from the select menus of the custom field? i.e. the ID that is used in the search => getall&field5=3 rather than getall&field5=orange
Reply With Quote
  #17  
Old 02-06-2005, 05:01 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1) WHERE field5 != ''
2) SELECT data from profilefield WHERE profilefieldid=5;
Then unserialize data and use the value returned by the other query as an index into this array.
Reply With Quote
  #18  
Old 02-06-2005, 05:38 AM
pshadow pshadow is offline
 
Join Date: Feb 2002
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks. first part worked perfect. I'm new to the whole query stuff so not sure what part 2 entails with the unserialize and using other query. I'll have to play around and with that one.

thanks for the quick response
Reply With Quote
  #19  
Old 02-06-2005, 05:48 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$field5 $DB_site->query_first("SELECT data FROM " TABLE_PREFIX "profilefield WHERE profilefieldid = 5");
$fieldvalues unserialize($field5['data']);

$dbquery $DB_site->query("SELECT field5, COUNT(field5) AS total FROM " TABLE_PREFIX "userfield WHERE field5 != '' GROUP BY field5 ORDER BY total DESC");

while (
$queryrow $DB_site->fetch_array($dbquery))
    {
        
$f5stat .= $queryrow['total'] . " " $fieldvalues[$queryrow['field5']];
    } 
Reply With Quote
  #20  
Old 02-06-2005, 06:36 AM
pshadow pshadow is offline
 
Join Date: Feb 2002
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm.. doesn't seem to return anything? no errors though? just count number and blank. nothing for the fieldvalues.
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 02:48 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.06109 seconds
  • Memory Usage 2,263KB
  • Queries Executed 13 (?)
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)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (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_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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete