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

Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2004, 03:12 PM
obiwan8472 obiwan8472 is offline
 
Join Date: Sep 2002
Location: UK
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default VB3.. SQL query problem

Hi everyone,
I have a points system installed on my board board (VBr3).

I have several usergroups.. and a fair few public usergroups.

What I want to do is.. add up all the points from certain usergroups. I have an SQL query that does this ok. BUT the problem arises with the membergroupids when the lower numbers appear first.

Heres my current SQL.

SELECT SUM(points) FROM user WHERE usergroupid=13 AND membergroupids=13

usergroupid is fine.. that works. memergroups doesn't though because my test user has joined another group aswell.. so its in the table as 10,13,15.
It doesn't recoginise that he is number 13.. it just thinks his in 10.

Any ideas?
Thanks
Reply With Quote
  #2  
Old 01-24-2004, 04:52 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're just trying to extract the data per usergroup then you don't even need the:

PHP Code:
 AND membergroupids=13 
part of the query, because you're trying to find based on the usergroup not other membergroupids.

For instance if you're trying to find the sum for the Administrators usergroup the query will fail even if you add MySQL syntax to search the data of membergroupsid because it won't find the membergroupid of 6. If you're trying to incorporate membergroupids field then you should use 'OR' instead of 'AND'.

Hopefully that helps somewhat.

Cheers,
g-force2k2
Reply With Quote
  #3  
Old 01-24-2004, 09:44 PM
obiwan8472 obiwan8472 is offline
 
Join Date: Sep 2002
Location: UK
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmmm... the reason i am using membergroupid was because the members Primaryusergroup is Registered. I don't wish to sum that one up.
The ones i want to sum up are the Public Groups that the user ALSO belongs to.

As far as I can work out usergroupid is Primary Usergroup.. while membergroupid is the public or other usergroups that the user belongs to. In there you get listed 9,13,16 but the SQL i provided won't pick up that 13.. only the 9.
I want it to pick up the 9.
All my users are still in Registered.. but i am topping up their public usergroup bits.
Reply With Quote
  #4  
Old 01-25-2004, 12:25 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you have to do it this way:

[sql]SELECT SUM(points) FROM user WHERE usergroupid = 13 OR 13 IN (membergroupids)[/sql]

i think that should work
Reply With Quote
  #5  
Old 01-25-2004, 02:18 PM
obiwan8472 obiwan8472 is offline
 
Join Date: Sep 2002
Location: UK
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for time. I tried it.. but keep getting back NULL. I know theres some points in the membergroup 13 cuz I checked. But it won't work
Thanks for your time anyway. Ill continue tinkering.
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 04:53 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.04167 seconds
  • Memory Usage 2,195KB
  • 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
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete