user562854
user562854

Reputation:

Search in multiple columns

Having the following table schema:

id | english_name | russian_name | year
---------------------------------------
 5 |   The Book   |    Kniga     | 2008

and the given input: Kniga 2008;

Is it possible to reproduce the following steps?

Upvotes: 1

Views: 261

Answers (1)

Jon Gjengset
Jon Gjengset

Reputation: 4236

It's not pretty, but:

SELECT * FROM books WHERE russian_name = ? OR english_name = ? OR CONCAT(russian_name, ' ', year) LIKE ? OR CONCAT(english_name, ' ', year) LIKE ?

where the query string is set to the first two question marks, and the second and third as:

'%' . str_replace ( ' ', '%', $query ) . '%'

Upvotes: 1

Related Questions