俗已入骨 2016-05-22 15:07:33 3497次浏览 0条回复 1 0 0
$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 数组里面的值了,求大神解救!

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册