M
M
Maxim Timofeev2016-06-10 20:56:52
MySQL
Maxim Timofeev, 2016-06-10 20:56:52

Why does count return the same data regardless of conditions?

There are 6 records in the table. Here is the action:

public function actionAddMoreGroupPosts($id,$page){
        $offset = ($page-1) * 20;
        $query = GroupPost::find()->with(['author'])->where(['group_id'=>$id])->orderBy('status_id DESC, id DESC')->offset($offset);
        return $query->count();
    }

returns 6 regardless of $page.
The most interesting thing is that this bike wrote because the standard for Yii - Pagination returned the same thing.
Where am I fool?
In debug I look at the request:
SELECT COUNT(*) FROM `group_post` WHERE `group_id`='2' ORDER BY `status_id` DESC, `id` DESC

i.e. offset($offset) doesn't work at all

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2016-06-10
@ThunderCat Куратор тега MySQL

а полученный запрос после конструктора не смотрели? Иногда помогает - визуально оценить что наваяли если все мысли кончились )

M
MaxFreedom, 2016-06-10
@RomanticOS

Try writing: return $query->count([0]); In general, I can’t understand what Count should be returned, id or some other field.

Дмитрий Ким, 2016-06-10
@kimono

Может нужно указать ->limit()?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question