Multiple keyword search.
Posted: Fri Feb 09, 2007 12:49 am
I have a basic SQLite table with various short entries. I am creating a simple search by doing something like:
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:
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?
Code: Select all
$term = $_POST['search'];
$query = "SELECT * FROM Posts WHERE title LIKE '%".$term."%'";
$result = $db->arrayQuery($query,SQLITE_ASSOC);Code: Select all
$searchquery = $_POST['search'];
$keywords = explode(' ',$searchquery);