当前位置: 移动技术网 > IT编程>开发语言>PHP > Yii1.1中通过Sql查询进行的分页操作方法

Yii1.1中通过Sql查询进行的分页操作方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

inu-049,爱与哀愁古琴,幻宇玄宙

控制器中方法:

public function actiontindex(){
    $user = yii::app()->user;
    $id = $user->id;
    $connection=yii::app()->db;
    $sql= "sql查询语句";
    $command = $connection->createcommand($sql)->queryall();
    $pages = new cpagination(count($command));
    $list = $connection->createcommand($sql." limit ".$pages->limit." offset ".$pages->offset."")->queryall();
    $this->render('index',array(
      'bonus' => $list,
      'pages' => $pages,
    ));
  }

视图中显示为:

第一部分为查询的结果显示:

<table class="table table-bordered">
      <thead>
      <tr>
        <th class="per10">公文类型</th>
        <th class="per50">公文标题</th>
        <th class="per15">当前步骤</th>
        <th class="per15">日期</th>
      </tr>
      </thead>
      <tbody>
      <?php if (isset($bonus)):?>
        <?php foreach ($bonus as $key=>$ad): ?>
          <tr>
            <td><?=$ad['typename'] ?></td>
            <td><?=$ad['doc_title'] ?></td>
            <td><?=$ad['taskname'] ?></td>
            <td><?=date("y-m-d h:i:s",$v['create_time']) ?></td>
          </tr>
        <?php endforeach; ?>
      <?php endif; ?>
      </tbody>
    </table>

第二部分为分页的显示:

<?php
$this->widget('clinkpager',array(
    'header'=>'',
    'firstpagelabel' => '首页',
    'lastpagelabel' => '末页',
    'prevpagelabel' => '上一页',
    'nextpagelabel' => '下一页',
    'pages' => $pages,
    'maxbuttoncount'=>8,
    'cssfile'=>false,
    'htmloptions' =>array("class"=>"pagination"),
    'selectedpagecssclass'=>"active"
  )
);
?>

以上所述是小编给大家介绍的yii1.1中通过sql查询进行的分页操作,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网