haimingyoung 2015-06-30 17:09:59 8592次浏览 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',
    

    ]);

    1 条回复
    回复于 2021-08-31 10:39 回复

    这个model(),报错了,Call to undefined method andejian\models\AdjHospital::model(), 是什么原因?

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