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 10-04-2007, 07:29 AM
kafi kafi is offline
 
Join Date: Apr 2004
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default membergroupids IN (18) doesnt work - why?

Can anybody help me with this querry? I have users that are in 2 membergroupids. That is 12 and 18.
When I write condition membergroupids = 12 it works fine and it pull out ousers that are in 12 membergroupids (aka additional usergroup). I guess this works only because 12 is recorderd as first id in table... 12,18...
But when i try conditional membergroupids = 18; or I try membergroupids IN (18) neither doesnt work.

Any idea why? How to accomplish this querry? Is it because there are two "IN" in the querry???

This is what I try and doesnt work for me:
PHP Code:
$query4 $vbulletin->db->query("SELECT userid FROM user WHERE userid IN ($user) and membergroupids IN (18)"); 
while (
$row4 $vbulletin->db->fetch_array($query4)) {
     echo 
$row4['userid'].";";
     echo 
"<br />";

Milion thanks!!!
Reply With Quote
  #2  
Old 10-05-2007, 02:56 AM
WhaLberg's Avatar
WhaLberg WhaLberg is offline
 
Join Date: Nov 2006
Location: Dersaadet
Posts: 569
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you sure that there are users whose membergroupid is 18?
Reply With Quote
  #3  
Old 10-05-2007, 03:49 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have it backwards, it would be
Code:
18 IN (membergroupids)
but that won't work because it would parse the entire membergroupids list as a string and not a list.

Use,
Code:
find_in_set(18, membergroupids)
Reply With Quote
  #4  
Old 10-05-2007, 06:58 AM
kafi kafi is offline
 
Join Date: Apr 2004
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm I tried this:
PHP Code:
$query5find_in_set(18membergroupids);
echo 
$query5.";"
but I have got undefined function - probably I didnt call this function? Is this function OK here anyway? Because i found it in functions.php and it is about forums not about membergroupids... Well I am not coder so maybe I am doing something wrong...

Anyway i managed it with "membergroupids LIKE %18%" query and it works fine sofar.

Thanks for your help and any further feedback is appreciated .-)
Reply With Quote
  #5  
Old 10-05-2007, 07:18 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's a MySQL function not a PHP function.

Use it instead of IN
Reply With Quote
  #6  
Old 10-05-2007, 10:54 AM
nexialys
Guest
 
Posts: n/a
Default

[sql]SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid IN ($user) and membergroupids find_in_set(18, membergroupids)[/sql]

your way of doing the LIKE is not good as it will grab also members in group 118, 2187 etc... if you have that much usergroups.. lol
Reply With Quote
  #7  
Old 10-05-2007, 12:37 PM
kafi kafi is offline
 
Join Date: Apr 2004
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am aware of that
Ok so how to make it in correct way? I am getting syntax errror.

PHP Code:
$query5 $vbulletin->db->query("SELECT userid FROM user WHERE userid IN ($user) and membergroupids find_in_set(18, membergroupids)"); 
while (
$row5 $vbulletin->db->fetch_array($query5)) {
     echo 
$row5['userid'].";";
     echo 
"<br />"
Invalid SQL:
SELECT userid FROM user WHERE userid IN (17291,24998,19,8026,28994,56325) and membergroupids find_in_set(18, membergroupids);

MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'find_in_set(18, membergroupids)' at line 1
Error Number : 1064
Reply With Quote
  #8  
Old 10-05-2007, 12:41 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Should be:

PHP Code:
$query5 $vbulletin->db->query("SELECT userid FROM user WHERE userid IN ($user) and find_in_set(18, membergroupids)"); 
Reply With Quote
  #9  
Old 10-09-2007, 08:00 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And if you get touchy about vBulletin Coding Standards...
PHP Code:
$query5 $vbulletin->db->query("
    SELECT userid
    FROM user
    WHERE userid IN(
$user)
        AND FIND_IN_SET(18, membergroupids)
"
); 
Reply With Quote
  #10  
Old 10-09-2007, 12:14 PM
kafi kafi is offline
 
Join Date: Apr 2004
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, it is good to learn handy stuff from beginning

Thanks to all of you, your advice with find_ind_set is working great .-)
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 07:34 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.04239 seconds
  • Memory Usage 2,260KB
  • 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
  • (2)bbcode_code
  • (5)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
  • (9)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