简体   繁体   中英

how to search from comma separated column value in mysql

i have a search string $searchStr = 'anti' and have table mytable

  • id name keywords
  • 1 Avast antivirus,virus protection,alert
  • 2 Norton norton,antivirus
  • 3 Kesper antivirus,virus,kesper
  • 4 php php,mysql,code

i want to fetch data according to Keywords like if i search "anti" it fetch results with id 1,2,3

尝试这个

select * from table WHERE Keywords like '%anti%';

If you use mysqli :

$stmt = $mysqli->prepare('SELECT * FROM mytable WHERE find_in_set(?, myField) <> 0');
$stmt->bind_param('s', $searchStr);
$stmt->execute();

Use the FIND_IN_SET function.

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