Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Get Total Male/Female Members Details »»
Get Total Male/Female Members
Version: , by grb123 grb123 is offline
Developer Last Online: Jul 2003 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 03-12-2002 Last Update: Never Installs: 0
 
No support by the author.

I've set up a custom profile field for members to enter M for Male and F for Female. I've done similar custom fields for age groups and income, and I now want to display the totals for each group on a stats page.

Basically, I've tried to do a query that fetches info from the custom field Gender (profilefield=19) and prints a total of Male members and a total for Female. So in other words if profilefieldid19 has "M" in it, return the total "M's", and same for "F". Only because I know so little about MySQL I'm not getting very far!

I'm sure it would be very easy for one of you gurus out there!

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 03-12-2002, 02:26 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
$totals = $DB_site->query_first("SELECT SUM(IF(field19='M',1,0)) AS male,SUM(IF(field19='M',1,0)) AS female FROM userfield");
Then use $totals[male] and $totals[female].

You can also do this in two COUNT queries, btw.
Reply With Quote
  #3  
Old 03-12-2002, 02:29 PM
grb123 grb123 is offline
 
Join Date: Nov 2001
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, I wasn't even close!!!

Thanks Firefly!

I take it if I had more than two variables, say for example for the age groups where there are 4 (A, B, C & D where A=Under 18, B=18-30 etc) I would just add extra AS statements as per your answer?
Reply With Quote
  #4  
Old 03-12-2002, 02:31 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, but that could also slow down the query.
Reply With Quote
  #5  
Old 03-12-2002, 02:33 PM
grb123 grb123 is offline
 
Join Date: Nov 2001
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. That shouldn't be a problem because it's only for the site owners, not for general public viewing.

How else would you suggest doing it with more than 2 variables?
Reply With Quote
  #6  
Old 03-12-2002, 02:35 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
$malecount = $DB_site->query_first("SELECT COUNT(*) AS total FROM userfield WHERE field19='M'");
$femalecount = $DB_site->query_first("SELECT COUNT(*) AS total FROM userfield WHERE field19='F'");
etc.
Reply With Quote
  #7  
Old 03-12-2002, 03:33 PM
grb123 grb123 is offline
 
Join Date: Nov 2001
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah, brilliant - thank you very much!

That's kinda what I was trying to do, but you do it so much better!
Reply With Quote
  #8  
Old 03-12-2002, 03:34 PM
Freddie Bingham's Avatar
Freddie Bingham Freddie Bingham is offline
 
Join Date: Oct 2001
Posts: 506
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

or
Code:
SELECT count(*) AS count, field9 AS gender
FROM userfield
WHERE field9 = 'M' or field9 = 'F'
GROUP BY field9
Reply With Quote
  #9  
Old 03-12-2002, 03:47 PM
grb123 grb123 is offline
 
Join Date: Nov 2001
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Brilliant- thanks very much for your help guys! Much appreciated.
Reply With Quote
  #10  
Old 03-12-2002, 04:20 PM
grb123 grb123 is offline
 
Join Date: Nov 2001
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, next query...

How can I display the percentage of each variable?

For example, if there are 4 Males and 6 Females (ie 40% Male and 60% Female), how can I automatically take the totals and display the percentages?
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:46 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.04107 seconds
  • Memory Usage 2,287KB
  • Queries Executed 23 (?)
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
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)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
  • (9)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_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