按照时间段查询between

$map['regtime'] = array('between',[$_GET['starttime'],$_GET['endtime']]);
/**
     * 查询用户
     */
    public function fetchAction()
    {   
        $_GET['endtime']=strtotime($_GET['endtime']);
        $_GET['starttime']=strtotime($_GET['starttime']);
        //var_dump($_GET['starttime']);exit;
        // 考虑分页
        $pagesize = 10;
        $page = I('get.p', '1');

        $m_user = M('User');
        // 通用查询条件
        //$cond['is_deleted'] = '0';
        // $userForm=M('user'); 
        //$where['phone']=array('like','131%');
        if ($_GET['phone']) {
            $where['phone']=$_GET['phone'];
        }
        if ($_GET['name']) {
            $where['name']=$_GET['name'];
        }
        if ($_GET['idnumber']) {
            $where['idnumber']=$_GET['idnumber'];
        }
        if ($_GET['starttime']) {
            $where['regtime'] = array('gt',$_GET['starttime']);
        }
        if ($_GET['endtime']) {
            $where['regtime'] = array('lt',$_GET['endtime']);
        }
        $map['regtime'] = array('between',[$_GET['starttime'],$_GET['endtime']]);

        //$where['regtime'] > $_GET['starttime'];
        //$where['regtime'] > $_GET['starttime'];
        //$where['_logic']='OR';

            $user_list = $m_user
            ->field('id,name,phone,idnumber,status,status,regtime,logintimes')
            ->where($map)
            ->order('id desc')
            ->page($page, $pagesize)

            ->select();

            echo $m_user->getLastSQL();
        foreach ($user_list as &$user) 
        {   
            $user['moneys'] = sprintf("%.2f", $user['moneys']);//将金额设置为两位浮点型
            $user['regtime'] = date("Y-m-d", $user['regtime']);
            $user['logintimes'] = date("Y-m-d", $user['logintimes']);
            $number=$user['status'];
            if ($number==1) {
                $user['status']="新用户";
            }elseif ($number==2) {
                $user['status']="审核中";
            }else {
                $user['status']="雷锋";
            }
        }
        $this->assign('user_list', $user_list);

        $total = $m_user->where($cond)->count();
        $t_page = new Page($total, $pagesize);
        $this->assign('page_html', $t_page->show());

        $this->display();

    }

你可能感兴趣的:(按照时间段查询between)