0

This is the music. table It contains artists and titles. Artists are separated by commas if more than one artist sing a song. I want to set up a search function so users can search for one artist, both artists, no artists and title etc.

Table music:

|      artist     |    title   |
|------------------------------|
|eminem,lil wayne |   no love  |
|kida             |   o'najr   |

User may search like this:

eminem no love
lil wayne no love
no love eminem
no love lil wayne

Also user can or can not type special chars like ' if user search:

kida onajr
kida o najr
kida o'najr

the result should be the same.

This is my code up to now:

$search_value = "...";
$query = "select * from `music` where `title` like '%$search_value%' or `artist` like '%$search_value%'";

But if I search lil wayne no love no results are shown.

M1X
  • 4,971
  • 10
  • 61
  • 123

1 Answers1

2

You should use MATCH AGAINST for those kinda search.

Zerquix18
  • 769
  • 6
  • 19
  • 1
    Like this? select * from `music` match(`title`, `artist`) against ('%$search_value%') This is giving me an error. – M1X Sep 23 '14 at 21:18
  • You've got to break your search values into single ones. That's not your LIKE pattern. – VMai Sep 23 '14 at 21:27
  • @rexhn You have to add `FULLTEXT(title,artist)` in your table, you have to remake it or do an ALTER TABLE. Read the documentation. – Zerquix18 Sep 23 '14 at 21:33