hosted by liquidweb


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

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
  #1  
Old 09-07-2002, 02:58 AM
dommymedia dommymedia is offline
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"

Reply With Quote


Sponsored Links
  #2  
Old 09-07-2002, 07:07 AM
bill_jpn bill_jpn is offline
Newbie
 
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
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
Why You Should Embrace Google Plus Blog 2013-03-08 09:18:17


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
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com 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?