0

I have a simple MySQL database keyword search that is functional. However results for the search are not being returned if the keywords are not in the same order as entered in the database.

For example searching for "dog cat mouse" will return a result, becuase this is the order that it is written in the database but searching for "dog mouse cat" will return no results. Here is my code.

$sql = "SELECT * FROM table WHERE title LIKE '%$q%' OR date LIKE '%$q%' OR keywords LIKE '%$q%' ORDER BY date";

Any help on how to fix this issue would be greatly appreciated.

James

2
Contributors
1
Reply
1
Views
1 Week
Discussion Span
Last Post by pty
1

but searching for "dog mouse cat" will return no results

This is what your query is specifying. To make it match a jumble of words you need to can split up the string and group your criteria with and. This will soon get messy, especially if your searching across multiple columns. Depending on the database you're using I would change the query to use a full text search (available in most RDBMS in one form or another, including PostgreSQL and MySQL).

Edited by pty

Votes + Comments
And +1
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.