$where['class_id'] = ['in', '$cid_all']; $where['id'] = ['in', $all_user_id];//或這樣子 $where['title'] = ['like', '%php%']; $where['id'] = ['<>', $id]; $where['id'] = ['notin', $all_user_id];//不等於
與find_in_set()相反的函數能夠用!find_in_set() //值爲數字 $id=419; $where[] = ['exp',Db::raw("FIND_IN_SET($id,category)")];//category值爲數字,例子:419,415,414 //值爲字符串 $id值等於dfd 要注意'引號
$where[] = ['exp',Db::raw("FIND_IN_SET('$id',category)")];//category值爲數字,例子:'349/417/419','349/413/415','349/413/416' Db::name('menu')->where('FIND_IN_SET(:id,pid_all)',['id' => $id])->update([$field => $title]);
type 字段在數據庫是以 1,2,3 形式存在 已說到FIND_IN_SET函數的使用php
對於一些實在複雜的查詢,好比find_in_set,也能夠直接使用原生SQL語句進行查詢,例如:數據庫
Db::table('think_user') ->where('find_in_set(1,sids)') ->select();::table('think_user') ->where('find_in_set(1,sids)') ->select();
爲了安全起見,咱們能夠對字符串查詢條件使用參數綁定,例如:安全
Db::table('think_user') ->where('find_in_set(:id,sids)',['id'=>$id]) ->select();::table('think_user') ->where('find_in_set(:id,sids)',['id'=>$id]) ->select();
本身的實例:函數
$gonggaolist = Db::table("fa_cms_archives") ->alias('a') ->join("fa_cms_channel w","a.channel_id=w.id") ->where("w.parent_id=20 and a.status='normal'") ->where("FIND_IN_SET('recommend',a.flag)") ->order("a.id desc") ->field("a.id,a.channel_id,a.title,a.likes,a.image,w.diyname,a.updatetime,a.flag") ->limit("4") ->select(); dump($gonggaolist);
效果圖spa