vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   VB3.. SQL query problem (https://vborg.vbsupport.ru/showthread.php?t=60673)

obiwan8472 01-24-2004 03:12 PM

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

g-force2k2 01-24-2004 04:52 PM

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

obiwan8472 01-24-2004 09:44 PM

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.

Xenon 01-25-2004 12:25 AM

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 :)

obiwan8472 01-25-2004 02:18 PM

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.


All times are GMT. The time now is 07:01 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.01045 seconds
  • Memory Usage 1,717KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete