我想使用 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)
.
更多信息:
这篇关于在 yii2 中使用限制范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!