vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How do I...MySQL %LIKE% query (https://vborg.vbsupport.ru/showthread.php?t=70666)

eblivion 10-16-2004 02:51 PM

How do I...MySQL %LIKE% query
 
How do I query the database using LIKE for an array but getting only results containing the full words instead of parts of it.

Here's a little chunk of what I have so far:

$keywords = explode(' ',$searchterm) ;

for ($i = 0; $i < sizeof($keywords); $i++){
$sql5b .= "description LIKE '%{$keywords[$i]}%'";
}

I have the query working, the problem is if one of the keywords is "class", the query will return results for: class, classic, midclass, classify, etc....

What I want to know is how to do the query where it will only return results for the word class and not other words containing it.

JulianD 10-24-2004 07:54 AM

Quote:

Originally Posted by eblivion
How do I query the database using LIKE for an array but getting only results containing the full words instead of parts of it.

Here's a little chunk of what I have so far:

$keywords = explode(' ',$searchterm) ;

for ($i = 0; $i < sizeof($keywords); $i++){
$sql5b .= "description LIKE '%{$keywords[$i]}%'";
}

I have the query working, the problem is if one of the keywords is "class", the query will return results for: class, classic, midclass, classify, etc....

What I want to know is how to do the query where it will only return results for the word class and not other words containing it.

Hummm... Maybe adding white spaces around the keyword?

... WHERE description LIKE '% class %'

eblivion 10-28-2004 02:53 PM

Thanks. That's what I ended up doing....

The only drawback is if the word is at the beginning/end of the description and there's no white space before/after it.

Since this may occur in only a few searches, it's adequate for now.

~ Thanks again ~

Andreas 10-28-2004 02:55 PM

You might also want to use mySQL fulltext searching.


All times are GMT. The time now is 08:42 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.00906 seconds
  • Memory Usage 1,714KB
  • 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_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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