I want to get data from db using limit 12,20 .
Here is my code:
$Query = new Query;
$Query->select([\'um.id as USERid\', \'
Try this:
$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()
specifies the starting point and limit()
specifies the Number of records. If you want records between 12
and 20
then use limit(8)
.
For More Info:
you can do with Active record
$model = YourModel::find()->where('user_id = :user_id', [':user_id' => \Yii::$app->user->id])->limit(12,20)->all();
OR
$model = YourModel::find()->where('user_id = :user_id', [':user_id' => \Yii::$app->user->id])->with(['job','job.jobRecipient'])->limit(12)->all();