Multiple keyword search.

JavaScript and client side scripting.

Moderator: General Moderators

Locked
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Multiple keyword search.

Post by abeall »

I have a basic SQLite table with various short entries. I am creating a simple search by doing something like:

Code: Select all

$term = $_POST['search'];
$query = "SELECT * FROM Posts WHERE title LIKE '%".$term."%'";
$result = $db->arrayQuery($query,SQLITE_ASSOC);
It works great, but what I would like to do is be able to search for multiple keywords at once. How would this be done? Do I need multiple LIKE commands, or can it be combined? I figured I would convert commas to spaces, then explode the string by spaces to determine the unique keywords, something like:

Code: Select all

$searchquery = $_POST['search'];
$keywords = explode(' ',$searchquery);
But then I'm not sure how to search for Posts which contain any one of those keywords, or than create a bunch of OR title LIKE $keywords[x]. Any better suggestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Duplicate thread. Locked.
Locked