本文介紹了在 Laravel 中找到?例子的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是 Laravel 的新手.我的查詢是我需要從逗號分隔的字段中找出值.
I am new in laravel. My query is i need to find out value from comma separated field.
這是我的桌子:
tags_value
╔════╦══════════════╗
║ id ║ tags ║
╠════╬══════════════╣
║ 1 ║ css,html,php ║
║ 2 ║ php,java,css ║
║ 3 ║ java,c++,ios ║
╚════╩══════════════╝
這是我的 SQL 查詢:
This is my SQL query:
$query = DB::table('tags_value')
->whereRaw(FIND_IN_SET('css', Tags))
->get();
但它不起作用.
請幫我解決這個問題.提前致謝.
Please help me to solve this problem. Thanks in advance.
推薦答案
您需要使用引號轉義對 FIND_IN_SET()
的調用:
You need to escape the call to FIND_IN_SET()
using quotes:
$query = DB::table('tags_value')
->whereRaw('FIND_IN_SET(css,Tags)')
->get();
如果你想參數化你在FIND_IN_SET
中搜索的列,那么你可以嘗試這樣的事情:
If you want to parameterize the column for which you search in FIND_IN_SET
, then you can try something like this:
$colname = 'css'
$query = DB::table('tags_value')
->whereRaw('FIND_IN_SET(?,Tags)', [$colname])
->get();
這篇關于在 Laravel 中找到?例子的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!