tp5修复group by后分页异常

浏览:4096 发布日期:2017/01/19 分类:ThinkPHP5专区 关键字: tp5修复group by后分页异常
框架:tp5.0.0

发现类似$model->group('area_id')->paginate(2)的分页不对,修改\thinkphp\library\think\Query的count方法(494行)如下:public function count($field = '*')
    {
        $options = $this->getOptions();

        /*
         * 修复group情况下count不正确
         * @author 王荣 老倪
         * @version 2017.1.19 
         */
        if($options['group']){
            $bind    = $this->bind;

            //构建lists sql
            $lists = $this->options($options)->field('count(*)')->bind($bind)->fetchSql(true)->select(); 

            //构建子查询统计sql
            $sql = "select count(*) as tp_count from ($lists) a";

            $resultSet = $this->query($sql, $bind);

            return $resultSet[0]['tp_count'];
        }

        return $this->value('COUNT(' . $field . ') AS tp_count', 0);

    }
https://www.olcms.com/2036
最佳答案
评论( 相关
后面还有条评论,点击查看>>