Yii查询怎么返回结果的条数

weixin_38051062 2019-09-11 03:27:07
RT
...全文
27 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38069981 2019-09-11
  • 打赏
  • 举报
回复
->count()算是一种
weixin_38075729 2019-09-11
  • 打赏
  • 举报
回复
如果用CActiveDataProvider的话,可以用$dataProvider->totalItemCount取得总数。
weixin_38088281 2019-09-11
  • 打赏
  • 举报
回复
// 获取满足指定条件的行数 $n=Post::model()->count($condition,$params);
weixin_38111003 2019-09-11
  • 打赏
  • 举报
回复
不论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);
weixin_38114442 2019-09-11
  • 打赏
  • 举报
回复
$row=Post::model()->count($condition,$params);
weixin_38122514 2019-09-11
  • 打赏
  • 举报
回复
如果你写的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();
weixin_38125655 2019-09-11
  • 打赏
  • 举报
回复
yii::app()->db->createCommand($sql)->query()->rowCount

474

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧