我想使用限制12,20从db获取数据.
这是我的代码:
$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();
它不起作用.它给了我所有的行.我也试过 – > gt;限制([12,20]),不工作.
但是当我使用limit(12)时,我得到了12行.
我想获得限制12,20的行.在我的代码中我应该怎么做?
最佳答案
试试这个:
原文链接:https://www.f2er.com/mysql/434198.html$Query = new Query;
$Query->select(['um.id as USERid','COUNT(g.id) as guestCount'])
->from('user_master um')
->join('LEFT JOIN','g.user_id = um.id')
->limit(20)
->offset(12)
->groupBy('um.id')
->orderBy(['um.id' => SORT_DESC]);
Offset()指定起始点,limit()指定记录数.如果你想要12到20之间的记录,那么使用limit(8).
更多信息:
> http://www.bsourcecode.com/yiiframework2/select-query-model/#offset
> http://www.yiiframework.com/doc-2.0/yii-db-querytrait.html#offset%28%29-detail