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

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).

commented: And +1 +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.