0

I have this mysql query which searches for a specific word. For example lets make a search for Killzone Shadow Fall(stored in a variable):

select * from games where title like 'Killzone Shadow Fall'

It returns empty. Though this entry exist in the database as 'Killzone: Shadow Fall'

What should be done in order to return 'Killzone: Shadow Fall' when someone searches for 'Killzone Shadow Fall'?

3 Answers3

1

You don't need to escape colon, try changing to:

select * from games where title like 'Killzone%'

This will return all records from table where title field's value starts with Killzone.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

The _ character in LIKE replaces only 1 character in a string :

select * from games where title like 'Killzone_ Shadow Fall'

But it would be preferable to use % to have a larger set of occurence matching your search.

Oliboy50
  • 2,661
  • 3
  • 27
  • 36
0

I'd suggest replacing " " with %.

$searchTerm = "Killzone Shadow Fall';

$query = 'SELECT * FROM games WHERE title LIKE "'.str_replace(' ','%',$searchTerm).'"';
J A
  • 1,776
  • 1
  • 12
  • 13