yii2:多条件多where条件下碰到between时,between语句如何处理呢?

我有一张表:
id,name,telphone,ticket_no,status,create_time等字段,

在出具多条件查询时(当不涉及到时间范围或其他范围),可以用如下语句:

if (!empty($params[‘id‘])) {
    		$where_condition[‘oid‘] = $params[‘id‘];
    	}
    	if (!empty($params[‘post_name‘])) {
    		$where_condition[‘post_name‘] = $params[‘post_name‘];
    	}
    	if (!empty($params[‘telephone‘])) {
    		$where_condition[‘telephone‘] = $params[‘telephone‘];
    	}
    	if (!empty($params[‘ticket_no‘])) {
    		$where_condition[‘ticket_no‘] = $params[‘ticket_no‘];
    	}
    	if ($params[‘status‘] != -1) {
    		$where_condition[‘status‘] = $params[‘status‘];
    	}
        $where_condition[‘delete_flg‘] = 0;
    	$count = static::find()
    	->where($where_condition)
           ->andFilterWhere([‘between‘,‘CREATE_TIME‘,$start_date, $end_date])
    		->count();

  

当涉及到create_time时间范围查询时,那么问题来了,between怎么加进去?$where_condition[‘CREATE_TIME‘]=‘between 时间1 and 时间2‘ 这样是不行的,花了一点时间查询了下,yii2有这样的方法:andFilterWhere,使用方法如下:

->andFilterWhere([‘like1‘, ‘name‘, ‘%a%‘])

#当参数1,参数2为空时,between方法会自动过滤掉,也就是此条件会被删除不执行
 ->andFilterWhere([‘between‘, ‘created_at‘, 0(参数1), 1433088000(参数2)])

  

具体代码如下:

if (!empty($params[‘id‘])) {
    		$where_condition[‘oid‘] = $params[‘id‘];

    	}
    	if (!empty($params[‘post_name‘])) {
    		$where_condition[‘post_name‘] = $params[‘post_name‘];

    	}
    	if (!empty($params[‘telephone‘])) {
    		$where_condition[‘telephone‘] = $params[‘telephone‘];

    	}
    	if (!empty($params[‘ticket_no‘])) {
    		$where_condition[‘ticket_no‘] = $params[‘ticket_no‘];

    	}
    	if ($params[‘status‘] != -1) {
    		$where_condition[‘status‘] = $params[‘status‘];

    	}
        $start_date = $end_date = ‘‘;
        if($params[‘isSearch‘] == 1) {
            if (!empty($params[‘start_date‘]) && !empty($params[‘end_date‘])) {
                $start_date = strtotime($params[‘start_date‘]);
                $end_date = strtotime($params[‘end_date‘]) + 86400 - 1;

            }
        }
        $where_condition[‘delete_flg‘] = 0;

    		$count = static::find()
    		->where($where_condition)
            ->andFilterWhere([‘between‘,‘CREATE_TIME‘,$start_date, $end_date])
    		->count();

  

时间: 2024-08-13 00:05:13

yii2:多条件多where条件下碰到between时,between语句如何处理呢?的相关文章

jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件

/** * @@desc 文本框清除按钮,如果isAutoWrap为false当前文本框父级必须是relative定位,boostrap参考input-group * @@author bear.LEE <571115139#qq.com> * @@since 2018-08-21 **/ ; (function ($) { $.fn.extend({ addClearBtn: function (options, $o) { var deft = { symbolClass: "f

hell脚本编写 之 条件选择,条件判断,循环语句

1 概述 编写shell脚本,一般离不开条件选择,条件判断以及循环语句.掌握这三个语法,将大大提高脚本的编写效率,使得脚本编写更加灵活,完成X相对复杂的工作 2 条件选择if语句 if语句选择执行,逐条件进行判断,第一次遇为"真"条件时,执行其分支,而后结束整个if语句 if是根据判读条件的命令的退出状态来执行命令,if语句可嵌套 单分支 if 判断条件;then 条件为真的分支代码 fi 双分支 if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi 多分

bash脚本编程之条件判断、条件测试

脚本编程: 编程面向过程有如下几种执行方式 顺序执行 选择执行:  如 if, case 循环执行:  如 for, while, until bash的变量类型: 本地变量 set VAR_NAME=value 设置变量赋值 如: set User=Centos unset VAR_NAME 撤消变量赋值 如: unset User=Centos ${VAR_NAME} 作用范围:当前shell进程: 局部变量 local VAR_NAME=value 设置变量赋值 unset VAR_NAM

java中多条件与不定条件查询

java中多条件与不定条件查询 网站或各类管理系统都会用到搜索,会用到一个或多个不确定条件搜索,单条件搜索比较简单,有时候会有多个条件共同查询,如果系统中已经提供了相关的方法供你使用最好,像我做这老系统改版,需要添加搜索,就要自己写了.开始也没管那么多,就是拼sql,但是后来发现要加搜索地方不少,总是这样写既增加了工作量,还要做很多重复工作,说不定以后还会做这样的工作,所以还是写一个比较通用的查询方法. package com.test; import java.util.Iterator; i

yii2.0 访问控制器下的方法时出现 Object Not Found! 解决办法

yii2.0  访问控制器下的方法时出现 Object Not Found! 时 可以查看(apache)  入口文件index.php 的同级有没有 .htaccess 文件 没有.htaccess文件  要添加该文件 内容: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php 保存后重启apache

mybatis——逆向工程中 where (条件1)and (条件2 or 条件3 or 条件4)

where (条件1)and (条件2 or 条件3 or 条件4) = where (条件1 and 条件2)or (条件1 and 条件3) or (条件1 and 条件4) 结果 是这样的 WHERE ( birthdate between ? and ? and username like ? ) or( birthdate between ? and ? and email like ? ) or( birthdate between ? and ? and phone like ?

IE环境下判断IE版本的语句...[if lte IE 6]……[endif][if lte IE 7]……[endif]

IE下判断IE版本的语句...[if lte IE 6]--[endif] 复制代码 代码如下: <!--[if IE 6]> <![endif]--> 只有IE6版本可见 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if gte IE 6]> <![endif]--> IE6及其以上版本可见 <!--[if IE 7]> <![endif]--> 只有IE

linux下安装Oracle时交换空间不足的解决方法

摘:linux下安装Oracle时交换空间不足的解决方法 linux上安装Oracle时交换空间不足的解决办法 增加交换空间有两种方法: 严格的说,在系统安装完后只有一种方法可以增加swap,那就是本文的第二种方法, 至于第一种方法应该是安装系统时设置交换区. 1.使用分区: 在安装OS时划分出专门的交换分区,空间大小要事先规划好,启动系统时自动进行mount. 这种方法只能在安装OS时设定,一旦设定好不容易改变,除非重装系统. 2.使用swapfile:(或者是整个空闲分区) 新建临时swap

Firefox下网页缩放时防止div被挤到下一层

http://wu110cheng.blog.163.com/blog/static/13334965420121120102439190/ Firefox下网页缩放时防止div被挤到下一层 问题:三个div,一个div中包含两个浮动带有border边框的div:且样式设计中保证两个div全部宽度之和等于外层div的宽度.在火狐下缩放网页显示比例小于100%时,会导致右边div被挤到下一行. 案例: <style> *{ margin:0; padding:0;} #box{width:300