本文介紹了在 Laravel 中找到?例子的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我是 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.
推薦答案
您需要使用引號轉(zhuǎn)義對 FIND_IN_SET()
的調(diào)用:
You need to escape the call to FIND_IN_SET()
using quotes:
$query = DB::table('tags_value')
->whereRaw('FIND_IN_SET(css,Tags)')
->get();
如果你想?yún)?shù)化你在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();
這篇關(guān)于在 Laravel 中找到?例子的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!