如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<?php //使用use传入参数 $name = 'thinkphp'; $id = 10; Db::table('think_user')->where(function ($query) use($name, $id) { $query->where('name', $name) ->whereOr('id', '>', $id); })->select(); SELECT * FROM `think_user` WHERE ( `name` = 'thinkphp' OR `id` > 10 ) Db::table('think_user') ->where('name', ['like', 'thinkphp%'], ['like', '%thinkphp']) ->where(function ($query) { $query->where('id', ['<', 10], ['>', 100], 'or'); }) ->select(); SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' AND `name` LIKE '%thinkphp' ) AND ( `id` < 10 or `id` > 100 ) $id=1; $res = $model->table('channel') ->where('channel_id','NOT IN',function($query) use ($id) { $query->table('adv_channel_rule')->where("adv_id",$id)->field('channel_id'); })->select(); SELECT * FROM `channel` WHERE channel_id NOT IN (SELECT channel_id FROM adv_channel_rule WHERE adv_id='.$id.') // paginate // each 使用与分页之后进行遍历处理 $list = ProModel::alias('a') ->field('a.*,b.name as brand') ->join('changshang b','a.bid=b.id') ->where($where) ->order('sort desc,id asc') ->paginate($limit,false,['query' => request()->param()]) // ->paginate(10,true)//简介diamante ->each(function($item, $key){ $item['prices'] = db('product_price')->where(["id"=>$item['id']])->order("quantity asc")->select(); $item['packaging'] = db('param_child')->where(["id"=>$item['id'],"pid"=>"231"])->value('value'); $yr = db('changshang')->where(["id"=>$item['bid']])->value('ctime'); $item['yr'] = date("Y",time())-date("Y",$yr); return $item; });