简体   繁体   中英

php MySQL multiple words search

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.

您应使用MATCH AGAINST进行此类搜索。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM