想知道yii原生sql语句怎么分页? [ 新手入门 ]
$connection = Yii::$app->db;
$sql = "SELECT user_id,SUM(consumption) as consumption,SUM(achievement)
as achievement,SUM(total_bonus) as total_bonus,SUM(fudao_prize)
as fudao_prize,SUM(a_bonus) as a_bonus,SUM(income) as income
FROM ol_bonus GROUP BY user_id";
$command = $connection->createCommand($sql)->queryAll();
$pages = new Pagination(['totalCount' => count($command)]);
$list = $connection->createCommand($sql." limit ".$pages->limit." offset ".$pages->offset."")->queryAll();
$dataprovider = new ArrayDataProvider([
'allModels' => $list,
]);
return $this->render('check',[
'bonus' => $dataprovider,
'pages' => $pages,
]);
--视图
<?php if (isset($bonus)):?>
<?php foreach ($bonus as $key=>$ad): ?>
<tr>
<td><?=$ad['user_id'] ?></td>
<td><?=$ad['consumption'] ?></td>
<td><?=$ad['achievement'] ?></td>
<td><?=$ad['total_bonus'] ?></td>
<td><?=$ad['fudao_prize'] ?></td>
<td><?=$ad['a_bonus'] ?></td>
<td><?=$ad['income'] ?></td>
<?php endforeach; ?>
<?php endif; ?>
<?php
echo LinkPager::widget([
'pagination' => $pages,
]);
?>
初学yii框架,用原生sql语句去的数据表中多个字段的总共,但是不知道怎么把原生sql语句做分页,这是从网上找到的分页实例,但是这样用的话就取不到$bonus 数组里面的值了,求大神解救!
共 0 条回复
没有找到数据。
俗已入骨
注册时间:2016-05-22
最后登录:2017-03-31
在线时长:2小时25分
最后登录:2017-03-31
在线时长:2小时25分
- 粉丝1
- 金钱20
- 威望0
- 积分40