Reputation: 2647
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();
╔════╦══════════════╗
║ 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
Reputation: 233
Try this code,
$data = modelName::where('filedName', 'like', '%keyword%')->get();
Upvotes: 3
Reputation: 498
Use %
$Keyword = $_POST['keyword'];
$Result = DB::table('faqtopic')
->whereRaw('FIND_IN_SET(?,Keywords)', 'LIKE', '%'.$Keyword.'%')
->get();
Upvotes: 0