haimingyoung 2015-06-30 17:09:59 6049次浏览 3条回复 0 0 0

yii1.1 怎么统计查询 我想查出每个用户都发了多少篇文章。要怎么做?求大神指点!!!

亿速云
  • 回复于 2015-07-01 12:42 举报

    自己写sql:

    $sql = 'select username,count(*) from posts group by username';
    $ret = Yii::app()->db->createCommand($sql)->queryAll();
    var_dump($ret);
    
    1 条回复
    回复于 2015-07-04 17:51 回复

    那这样写如何使用分页CDbCriteria呢?

  • 回复于 2015-07-06 16:57 举报

    controller:
    $crite = new CDbCriteria;
    $crite->compare('branchid',$this->branchId);
    $count =PointsProduct::model()->count($crite);
    $pages = new CPagination($count);
    $pages->pageSize = 15;
    $pages->applyLimit($crite);
    $productList = PointsProduct::model()->with('stocks','brand')->findAll($crite);

    view:

                $this->widget('CLinkPager',array(
                       'header'=>'',
                       'firstPageLabel' => '首页',
                       'lastPageLabel' => '末页',
                       'prevPageLabel' => '上一页',
                       'nextPageLabel' => '下一页',
                       'pages' => $pages,
                       'maxButtonCount'=>8,
                        'cssFile'=>false,
                        'htmlOptions' =>array("class"=>"pagination"),
                        'selectedPageCssClass'=>"active"
                 )
                 );
    

    不知道是不是你需要的那个意思

  • 回复于 2019-12-26 17:14 举报

    $postList = Post::model()->findAll([

    'select'=>"id,user_id,count(*) as post_num",
    'condition' => "user_id={$user_id}",
    'order'=>'id desc',
    

    ]);

您需要登录后才可以回复。登录 | 立即注册