Mr.Happy
Mr.Happy

Reputation: 2647

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.

$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. I want to get android result If user pass andro keyword for search query.

Any Idea how to get this results.

Thanks.

Upvotes: 4

Views: 248

Answers (2)

keerti Sawlani
keerti Sawlani

Reputation: 233

Try this code,

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

Upvotes: 3

Vivek Pipaliya
Vivek Pipaliya

Reputation: 498

Use %

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

Upvotes: 0

Related Questions