简体   繁体   English

从逗号分隔中查找匹配的关键字

[英]Find matching keywords from comma separated

I am trying to find keywords from comma separating string with FIND_IN_SET and here is mysql query in Laravel framwork. 我试图从逗号分隔字符串与FIND_IN_SET找到关键字,这里是Laravel框架中的mysql查询。

$Keyword = $_POST['keyword'];
$Result = DB::table('faqtopic')
    ->whereRaw('FIND_IN_SET(?,Keywords)', 'LIKE', ''[$Keyword])
    ->get();

faqtopic table: 常见问题表:

╔════╦══════════════╗
║ id ║   keywords   ║
╠════╬══════════════╣
║  1 ║ php, android ║
║  2 ║ microsoft,net║
║  3 ║ android, ios ║
╚════╩══════════════╝

I am getting two results, If I pass android keyword but not getting any result I pass only andro . 我得到两个结果,如果我传递android关键字但没有得到任何结果我只通过andro I want to get android result If user pass andro keyword for search query. 我想得到android结果如果用户传递了搜索查询的andro关键字。

Any Idea how to get this results. 任何想法如何得到这个结果。

Thanks. 谢谢。

试试这段代码,

$data = modelName::where('filedName', 'like', '%keyword%')->get();

Use % 使用 %

$Keyword = $_POST['keyword'];
$Result = DB::table('faqtopic')
    ->whereRaw('FIND_IN_SET(?,Keywords)', 'LIKE', '%'.$Keyword.'%')
    ->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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