Reputation:
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?
russian_name
for EXACT MATCH. If matched, return the row;english_name
for EXACT MATCHES.Kniga 2008
), then try to look among columns and see if there is ANY COMBINATION of columns matched. In this particular case russian_name
and year
will match.-
, /
, :
so if the given input is: The Book / Kniga 2008
or is The Book : 2008
, the results should still contain the row above.Upvotes: 1
Views: 261
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