2013-09-23 12:28:45 22355次浏览 7条回答 0 悬赏 0 金钱

RT

  • 回答于 2013-09-23 15:26 举报

    ->count()算是一种

    1 条回复
    回复于 2013-09-23 15:27 回复

    +1

  • 回答于 2013-09-23 15:27 举报

    如果用CActiveDataProvider的话,可以用$dataProvider->totalItemCount取得总数。

    1 条回复
    回复于 2016-01-21 15:41 回复

    感谢 赐教,谢谢

    觉得很赞
  • 回答于 2013-09-23 15:28 举报
    // 获取满足指定条件的行数
    $n=Post::model()->count($condition,$params);
    
  • 回答于 2013-09-23 15:31 举报

    不论AR 还是 DAO count函数应该都行吧

    ar 返回的是对象,dao返回的是数组,count下长度都

    dao中

    execute(): 执行一个无查询 (non-query)SQL语句, 例如 INSERT, UPDATE 和 DELETE 。如果成功,它将返回此执行所影响的行数。

    AR中

    // 获取满足指定条件的行数
    $n=Post::model()->count($condition,$params);
    // 通过指定的 SQL 获取结果行数
    $n=Post::model()->countBySql($sql,$params);
    
  • 回答于 2013-09-23 15:36 举报
    $row=Post::model()->count($condition,$params);
    
  • 回答于 2013-09-23 15:36 举报
    • 如果你写的SQL语句比较简单,建议使用下面的方法:
    //得到行数目或者其他数目 count
    // get the number of rows satisfying the specified condition
    $n=Post::model()->count($condition,$params);
    // get the number of rows using the specified SQL statement
    $n=Post::model()->countBySql($sql,$params);
    // check if there is at least a row satisfying the specified condition
    $exists=Post::model()->exists($condition,$params);
    
    • 如果你写的SQL语句比较复杂,建议使用下面的方法:
    $sql = "SELECT ...... FROM .........LEFT JOIN  offer o ON o.`offer_id`=......";
    
    $total_sql = "SELECT COUNT(o.offer_id) num ".strstr($sql, 'FROM');
    
    $this->connection->createCommand($total_sql)->queryScalar();
    
  • 回答于 2013-09-23 15:43 举报
    yii::app()->db->createCommand($sql)->query()->rowCount
    
您需要登录后才可以回答。登录 | 立即注册
cl880926
实习生

cl880926

注册时间:2013-09-23
最后登录:2013-11-16
在线时长:0小时0分
  • 粉丝1
  • 金钱10
  • 威望0
  • 积分10

热门问题