Gian
Gian

Reputation: 31

PHP MYSQL search keywords

I have a input field that search's for keywords in my database. Say the title of a car listing is "Toyota surf 1990 SSR-X", I want to be able to search something like "Toyota 1990", how can I achieve this?. If I search "Toyota surf" or "surf 1990" it works.

$query = "SELECT * FROM cars WHERE title LIKE '%" . $search_keywords . "%'";

Upvotes: 1

Views: 84

Answers (1)

Themud
Themud

Reputation: 58

$query = "SELECT * FROM cars WHERE title LIKE '%" . $search_keywords . "%'";

That code used in MySQL, so it doesn't have any relates with the main PHP coding.

Try using the preg_match feature instead. Here is an example:

preg_match("KEYWORDS", $variable)

And you could add an if statement. Like the following:

if(preg_match("KEYWORDS", $variable))

I wish I could give you the solution that you are requesting for.

Upvotes: 3

Related Questions