M
M
Messi2018-07-23 18:58:33
Yii
Messi, 2018-07-23 18:58:33

How to count COUNT with condition in DataProvider?

Hello! Prompt, please:
There is MyModelSearch
In the method public function search($params)
I write $query = MyTable::find()->....,
and I get dataProvider.
I passed this dataProvider to the view in GridView and I display all the columns from the MyTable table.
For example, 40 entries in the temperature column are displayed.
How to display the Count(temperature > 10) value separately from the GridView on the page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-07-23
@FitTech

Count(temperature > 10)?

What is it? You talked for a long time about the standard code from gii and then, completely out of the blue, the concepts "temperature", "10", "Count" came from the ceiling.
I deciphered this as the number (40 records of the temperature > 10 column), but 40 records of the temperature > 10 column is apparently either true or false, and I don’t understand what you expect from counting the amount of bowline.
dataProveder has a getModels method that gives an array of models, and a helper like ArrayHelper::column can pull a column. It is probably necessary to calculate the sum of the values ​​​​in the temperature column, and not the quantity, because the quantity is equal to the limit, regardless of the column.

L
Lander, 2018-07-23
@usdglander


I write $query = MyTable::find()->....
and get dataProvider.
But no! You get Query.
You can withdraw the amount using
$query->count();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question