php tp5和tp6 多条件查询的区别

10 篇文章 0 订阅
4 篇文章 0 订阅
		//tp5
		$lable_id = $this->request->post('lable_id', '', 'trim,strip_tags');
        if ($lable_id) {
            $where['intention_label'] = ['like', '%' . $lable_id . '%'];
        }
        $font_person = $this->request->post('font_person', '', 'trim,strip_tags');
        if ($font_person) {
            $array = json_decode($font_person, true);
            if ($array) {
                $where['front_charge'] = ['in', $array];
            }
        }
		
		//find in set
		if (!in_array(1, $this->user->role)) {
           $id = $this->user->id;
           $where[] = ['exp', Db::raw("FIND_IN_SET(" . $id . ",b_customer_id)")];//b_customer_id为数据库字段名例:1,2,3,4
       }
	



		//tp6
		$like = [];
		$cate_id = [];
        if (isset($param['keyworld'])){
            $like = [['title','like', '%'.$param['keyworld'].'%']];
        }
        if (isset($param['cate_id']) && $param['cate_id'] != '') {
            $cate_id = [['cate_id', 'in', explode(',', $param['cate_id'])]];//分类id
        }
        
        //多个字段模糊查询
        $model = new News();
        if (isset($param['keywords_']) && $param['keywords_'] != '') {
            $model = $model->where('title|descs|content', 'like', '%' . $param['keywords_'] . '%');
        }
        $data = $model->order('sort desc,id desc')->select();
		
		//between
		$where = [];
        $start = strtotime(date("Y-m-d H:i:s", strtotime($param['start_time'])));
        $end = strtotime(date("Y-m-d H:i:s", strtotime($param['end_time']) + 86399));
        $where[] = ['create_time', 'between', "{$start},{$end}"];
		
		//find in set
		if (!in_array(1, $this->user->role)) {
            $id = $this->user->id;
            $where[] = ['', 'exp', Db::raw("FIND_IN_SET($id,head)")];//head为数据库字段名例:1,2,3,4
        }
        
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值