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 02-15-2004, 05:08 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default MySQL and multiple likes

Observe:
PHP Code:
$result $DB_site->query("SELECT userid, username, vbms_alias,
        IF(options & " 
$_USEROPTIONS['emailonpm'] . ", 1, 0) AS emailonpm
        FROM " 
TABLE_PREFIX "user
        WHERE vbms_alias != \"\" AND LCASE(vbms_alias) NOT IN (
$bannedaliases)"); 
Note the NOT IN portion. I want to match against a series of LIKE matches ("%alias1%", "%alias2%", etc.). I can figure out how to match against a single alias with LIKE or a group of aliases exactly with IN, but not both. Ideas?
Reply With Quote
  #2  
Old 02-15-2004, 06:56 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not sure entirely what you're trying to do but have you looked into mysql's regexp capabilities - that may do it for you
Reply With Quote
  #3  
Old 02-15-2004, 08:42 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
Not sure entirely what you're trying to do but have you looked into mysql's regexp capabilities - that may do it for you
I'm trying to compare a single column to an array of values with a single query. That is, let's say MySQL is looking at the column "alias" with the value "nobody". I want it to check against "noreply", "webmaster", "administrator", and "nobody", and if any of those are found as a substring within the alias, it will skip the row.

A regex will work but checking against an array is still the issue.
Reply With Quote
  #4  
Old 02-16-2004, 09:29 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

MySQL has a built in substr function

Someone once showed me how it can be used as a search feature but i'm not entirely sure how to use it as a condition. I know it definately can be though. You could split you array into individual strings such as ' AND SUBSTR('ll',1)' or however it's used and then put $conditions at the end of your SQL query

With me?

Edit: http://www.mysql.com/documentation/m...61/content.htm
Reply With Quote
  #5  
Old 02-16-2004, 12:54 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
MySQL has a built in substr function

Someone once showed me how it can be used as a search feature but i'm not entirely sure how to use it as a condition. I know it definately can be though. You could split you array into individual strings such as ' AND SUBSTR('ll',1)' or however it's used and then put $conditions at the end of your SQL query

With me?

Edit: http://www.mysql.com/documentation/m...61/content.htm
Yes, I get what you're saying...it's just a very unclean solution IMO.
Reply With Quote
  #6  
Old 02-22-2004, 02:56 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So no other ideas, then?

Some contextual code if there's still confusion:
PHP Code:
// find out banned aliases and make them unroutable
debugecho("Caching banned aliases...");
$bannedaliases explode(" "$vboptions['vbms_bannedaliases']);
foreach (
$bannedaliases as $key => $value)
{
    
$bannedaliasesp[$key] = addslashes(strtolower($value));
}
$bannedaliases implode("%\", \"%"$bannedaliases);
$bannedaliases "\"" $bannedaliases "\"";

// ----------------------------------------------------------------------------

// cache users
/**
 * @todo remove username from query (only used for debugging)
 */
debugecho("Caching users...");
$result $DB_site->query("SELECT userid, username, vbms_alias, email,
        IF(options & " 
$_USEROPTIONS['emailonpm'] . ", 1, 0) AS emailonpm
        FROM " 
TABLE_PREFIX "user
        WHERE vbms_alias != \"\" AND LCASE(vbms_alias) NOT IN (
$bannedaliases)"); 
Reply With Quote
  #7  
Old 02-22-2004, 08:36 PM
Natch's Avatar
Natch Natch is offline
 
Join Date: Nov 2002
Location: Australia
Posts: 851
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

MySQL is powerful, but not PHP - your best bet is Mist/Dean's solution to build a list of banned aliases from your array - makes for a large query (number of characters) but it's really a quick query for SQL to run ...
Reply With Quote
  #8  
Old 02-22-2004, 09:22 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I ended up using a regular expression, delimiting everything with pipe characters.
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 12:21 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.04334 seconds
  • Memory Usage 2,243KB
  • 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_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete