/**
* THinkPHP5使用group by分页出现异常,无法正常使用
* 类似$model->group('area_id')->paginate(2)的分页出错,
* 修改\Thinkphp\library\think\db\Query.php的count()方法如下:
* 修复group情况下count不正确
* @author lifee
*/
public function count($field = '*')
{
$options = $this->getOptions();
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);
}
网友评论