vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL and multiple likes (https://vborg.vbsupport.ru/showthread.php?t=61597)

filburt1 02-15-2004 05:08 PM

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?

Dean C 02-15-2004 06:56 PM

Not sure entirely what you're trying to do but have you looked into mysql's regexp capabilities - that may do it for you :)

filburt1 02-15-2004 08:42 PM

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.

Dean C 02-16-2004 09:29 AM

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

filburt1 02-16-2004 12:54 PM

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.

filburt1 02-22-2004 02:56 PM

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)"); 


Natch 02-22-2004 08:36 PM

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 ...

filburt1 02-22-2004 09:22 PM

I ended up using a regular expression, delimiting everything with pipe characters.


All times are GMT. The time now is 12:11 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.01192 seconds
  • Memory Usage 1,741KB
  • 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
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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