封装sql语句中in限制查询个数的方法

    /*  
     * 此方法用于每天凌晨取前一天的回滚用户账号
     */
    public function getRollBackAccount($startTime,$endTime){
        
        //1.首先查询出当天的新增的用户账号    
        $sql_account = "SELECT DISTINCT `accountName`,`mTime` FROM `t_log_register` WHERE `mTime`>='{$startTime}' AND `mTime`<='{$endTime}'";
        $day_account = fetchRowSet($sql_account);

        foreach ($day_account as $key => $account) {
            $arr[] = $account['accountName'];    
           }

        // 统计回滚用户的时间范围限制两个月内  
        //$two_months_before_time = strtotime(date("Y-m-d", strtotime("-2 month")));
        $now_end_time = $endTime-86400;
        // 批量查询限制
        $count_account = count($arr);
        $base = 10;
        $group = floor($count_account / $base);
        for ($i=0; $i <= $group; $i++) { 
            echo  '<br>group: ' . $i . "<br>";
            $group_account = '';
            for ($j=0; $j < $base; $j++) { 
                $key = $i * $base + $j;
                if($key < $count_account) {
                    $group_account .= "'" . $arr[$key] . "',";
                }
            }
            $group_account = rtrim($group_account, ',');

            $sql_all_account = "SELECT DISTINCT `accountName`,`agentId`,`serverId`,`platform`,`mTime` FROM `t_log_register` WHERE `accountName` in ({$group_account}) AND `mTime` < '{$now_end_time}' ";
            $all_account = fetchRowSet($sql_all_account);    

               if(!empty($all_account)){
                  break;
               }     
        }
     
        $arr_account = array();
           foreach ($all_account as $key => $before_account) {
               $arr_account[$key]['agentId'] = $before_account['agentId'];
               $arr_account[$key]['serverId'] = $before_account['serverId'];
               $arr_account[$key]['platform'] = $before_account['platform'];
            $arr_account[$key]['accountName'] = $before_account['accountName'];
               $arr_account[$key]['mTime'] = $before_account['mTime'];    
           }
           return $arr_account;    
    }

 

转载于:https://www.cnblogs.com/lonmyblog/p/8277440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值