Use limit range in yii2?(在 yii2 中使用限制范围?)
问题描述
我想使用 limit 12,20 从数据库获取数据.
I want to get data from db using limit 12,20 .
这是我的代码:
$Query = new Query;
$Query->select(['um.id as USERid', 'um.first_name', 'um.last_name', 'um.email', 'COUNT(g.id) as guestCount'])
->from('user_master um')
->join('LEFT JOIN', 'guest g', 'g.user_id = um.id')
->limit(12,20)
->groupBy('um.id')
->orderBy(['um.id' => SORT_DESC]);
$command = $Query->createCommand();
$evevtsUserDetail = $command->queryAll();
它不起作用.它给了我所有的行.我也试过 ->limit([12,20]),没有用.
It is not working. It is giving me all rows. I also tried ->limit([12,20]), not working.
但是当我使用 limit(12) 时,我得到了 12 行.
But when I am using limit(12) then I am getting 12 rows.
我想在 limit 12,20 中获取行.在我的这段代码中,我应该怎么做?
I want to get rows in limit 12,20 . What should I have to do for that in my this code?
推荐答案
试试这个:
$Query = new Query;
$Query->select(['um.id as USERid', 'um.first_name', 'um.last_name','um.email','COUNT(g.id) as guestCount'])
->from('user_master um')
->join('LEFT JOIN', 'guest g', 'g.user_id = um.id')
->limit(20)
->offset(12)
->groupBy('um.id')
->orderBy(['um.id' => SORT_DESC]);
Offset()
指定起始点,limit()
指定记录数.如果您想要 12
和 20
之间的记录,请使用 limit(8)
.
Offset()
specifies the starting point and limit()
specifies the Number of records. If you want records between 12
and 20
then use limit(8)
.
更多信息:
- http://www.bsourcecode.com/yiiframework2/select-query-模型/#offset
- http://www.yiiframework.com/doc-2.0/yii-db-querytrait.html#offset%28%29-detail
这篇关于在 yii2 中使用限制范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 yii2 中使用限制范围?


基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01