V
V
Victor Umansky2017-05-26 23:41:51
Yii
Victor Umansky, 2017-05-26 23:41:51

How to make a request to calculate the rating?

Hello everyone, I can not make a correct query in the table to calculate the total number of ratings.
Table fields
id | performer_id | review | rateNum
The query itself, you need to calculate in the rateNum column

$countReviews = OrdersHasReviewsRating::find()
        ->asArray()
        ->where(['performer_id' => Yii::$app->user->id])
        ->all();

there are two entries, in the first rateNum = 5, and in the second rateNum = 3 and we get 8, I can’t figure out how to do all this correctly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlikDex, 2017-05-27
@Uman

Something like this

$sql = 'SELECT SUM(`rateNum`) as `sum` FROM `' . OrdersHasReviewsRating::tableName() . '` WHERE `performer_id`=:performer_id';
$ratingSummary = Yii::$app->db->createCommand($sql)
    ->bindValue(':performer_id', Yii::$app->user->id)
    ->queryScalar(); // или ->queryOne();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question