Answer the question
In order to leave comments, you need to log in
How to display records by filtering out copies of a specific field in yii2?
Good afternoon!
I'm trying to display records, filtering out copies:
$query = Product::find();
$pages = new Pagination([
'totalCount' => $query->count(),
'pageSize' => 15,
'forcePageParam' => false,
'pageSizeParam' => false,
]);
$products = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index', [
'products' => $products,
'pages' => $pages,
]);
SELECT code_medication, MIN(price) FROM tailings t GROUP BY code_medication LIMIT 50;
Answer the question
In order to leave comments, you need to log in
The error is thrown inside the handleClose function . You are trying to pass a non-existent function to the console. Hence this error
Mistake number 1 - remove the word "public"
Mistake number two - never do
this
SELECT DISTINCT code_medication, MIN(price) FROM tailings t GROUP BY code_medication LIMIT 50;
Product::find()
->distinct()
->select('code, MIN(price)')
->from('product')
->groupBy('code');
$subQuery = (new Query())->select('MIN(t2.price)')->from('tailings t2')->where('t2.code_medication = t.code_medication');
$query = Product::find()->from('tailings t')->where(['t.price' => $subQuery])->groupBy('t.code_medication');
$countQuery = clone $query;
$pages = new Pagination([
'totalCount' => $countQuery->count(),
'pageSize' => 15,
'forcePageParam' => false,
'pageSizeParam' => false,
]);
$products = $query->offset($pages->offset)->limit($pages->limit)->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question