hosted by liquidweb

Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : MySQL word search

Forum Jump

MySQL word search

Reply Post New Thread In Programming Discussion Subscription
Send news tip View All Posts Thread Tools Search this Thread Display Modes
New Member
Join Date: Sep 2002
Posts: 2

MySQL word search

Climbing the mySQL learning curve, need a hand.

I have a field with Company names, say 1-6 words. What is the best way to set up a multiple keyword query (assume AND search) to do a word search on company names? e.g. searching on "Ford Motor" should match "Ford Motor Company" but not "Waterford Motoring Mills"

Sponsored Links
Join Date: Sep 2002
Posts: 14
Do you also want "Ford Motor" to find such things as "Fordham Motoring" and "Motorboats by Fordham"? If so, one way to do it is,

$xArray = explode(" ", $search);
foreach($xArray as $key=>$value)
$searchWhere .= " (MySQL_Field like '$value%'
or MySQL_Field like '% $value')
and ";
// finish the final "and"
$searchWhere .= " MySQL_Field != ''";
// Make the query
$query = "SELECT * from TABLE where $searchWhere ";
// etc.

It's best of course to also clean the data; each term should be stripped of HTML and other code, and quotes and so on should be stripped. The foreach will fail if there's an empty $search so that's got to be tested too.


Related posts from
Title Type Date Posted
CloudLinux Releases Software for Web Hosts to Set Limits on Accounts Running MySQL Web Hosting News 2015-01-26 14:42:26
Google Releases Hosted Database Service Cloud SQL to General Availability Web Hosting News 2014-02-12 13:46:02
Google Cloud Provides Support For Native MySQL Connections Web Hosting News 2013-11-01 14:36:06
PHP And MySQL Scaling: Preparing A Startup For Growth Blog 2014-04-24 13:27:35
ICANN New gTLD Committee Bans Dotless Domains Web Hosting News 2013-08-16 15:20:19

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Log in with your username and password

Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Web Hosting News:
WHT Membership
WHT Membership



Welcome to

Create your username to jump into the discussion! is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.

(4 digit year)

Already a member?