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.

3

1 Answer 1

2

You should use MATCH AGAINST for those kinda search.

Sign up to request clarification or add additional context in comments.

3 Comments

Like this? select * from music match(title, artist) against ('%$search_value%') This is giving me an error.
You've got to break your search values into single ones. That's not your LIKE pattern.
@rexhn You have to add FULLTEXT(title,artist) in your table, you have to remake it or do an ALTER TABLE. Read the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.