76971

MYSQL: Like Method, Similar Words - But Don't Show the Searched Word

actually i use this method to show similar words for a search request..

$query = "SELECT * FROM searches WHERE Query LIKE '%$search%' ORDER BY Query";

if someone searches for "nelly" it looks up in the database for similar words

"nelly furtado, nelly ft. kelly"...

but i dont want to show up the searched word..

example: you've searched for nelly - try this too: <strong>nelly</strong>, nelly furtado, nelly ft.,

the bold word should not showed up again, because it's the searched word.. is there maybe a method with MATCH AGAINST? thank you!

Answer1:

Couldn't you just do something like ...WHERE Query LIKE "%$search%' AND Query <> '$search'...?

Case-insensitive: Query LIKE "%$search%' AND STRCMP(Query, '$search') == 0

Answer2:

Leniel - It might be due to capitalization that search term is still showing up, i.e. *LIKE "nelly"* will find "nelly", "Nelly", "NeLlY", etc. whereas * <> "nelly"* will <strong>only</strong> exclude "nelly" (lowercase) from the results.

Perhaps NOT LIKE would yield better results, or str_to_lower your input before it leaves PHP and compare it to LOWER(column_name) to match all cases.

Recommend

  • Print values from JS variable to div
  • combine 2 associative arrays where values match
  • Tooltip for pagination buttons in DataTables
  • Perl , html data and characters encoded in utf-8
  • Can't upload base64 image using cordova-plugin-file-transfer
  • Passing Query Parameters from HTML/JS App to Azure Server Script
  • Toast inside onClick method in Fragment
  • Youtube upload API and cordova / phonegap
  • Different builds of turn-based Game Center game can’t see each other’s matches
  • how to put include(phpfile) to variable?
  • jquery draggable stop event
  • undefined reference error due to use of static variables [duplicate]
  • Generating random numbers directly inside a .htaccess file
  • LIBRTMP Delphi: mapping of the DLL
  • Add spaces between words in spaceless string
  • How to create virtual printer with iOS Simulator?
  • Deduce parent class of inherited method in C++
  • How to use animated gif in Firemonkey?
  • matching similar elements in between two lists
  • Tools for understanding HTML layout
  • How to use Windows Media Foundation with UWP without a topology
  • jQuery: How to AJAXify WordPress Search?
  • Hide HTML elements without javascript, only CSS
  • JPA flush vs commit
  • Do I need to seed any random number generator before using EVP_PKEY_keygen of OpenSSL?
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • Declaring variable dynamically in VB.net
  • Transactional Create with Validation in ServiceStack Redis Client
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • Join two tables and save into third-sql
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal