# Adding values from database in Query

**URL:** <https://forum.wixstudio.com/t/adding-values-from-database-in-query/31822>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 20, 2019, 10:52pm UTC](https://forum.wixstudio.com/t/adding-values-from-database-in-query/31822 "2019-12-20T22:52:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [December 20, 2019, 10:52pm UTC](https://forum.wixstudio.com/t/adding-values-from-database-in-query/31822/1 "2019-12-20T22:52:00Z")

</div>

Hi,

I’m trying to achieve that when I query my Reviews database that it adds the total count of reviews for that ‘title’ but seem to be struggling…  
This is the basic code i have started with, I have played around with some variations but none work

```javascript
wixData.query("Reviews")
.eq("title", title)
.find()
.then((res) => {
let item = res.items[0]
$w('#ratingsDisplay').rating = item.rating;
$w('#ratingsDisplay').numRatings = item.count;
})

```

Another example that I can’t get to work

```javascript
wixData.query("Reviews")
.eq("title", title)
.find()
.then((results) => {
console.log(results);                 
let items = results.items;
let value = items[i].count;  
$w('#ratingsDisplay').rating = results.rating; 
$w('#ratingsDisplay').numRatings = sumTotal;     
console.log(value);
console.log(sumTotal);
let sumTotal = 0
for (var i = 0; i < value.length; i++) {
sumTotal = sumTotal + value;
}
})

```

Would someone be bale to help me get the total count? Rating works fine (although it would be helpful if the result was 0 that it showed the default ‘No Reviews for this course’ text)

Many thanks in advance

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [December 20, 2019, 11:56pm UTC](https://forum.wixstudio.com/t/adding-values-from-database-in-query/31822/2 "2019-12-20T23:56:08Z")

</div>

Are you using or have you seen either of the two tutorials for ratings and reviews listed here?

[Corvid Tutorial: Adding Ratings and Reviews to a Wix Stores Site](https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site)  
[Corvid Tutorial: Capturing and Displaying Ratings](https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings)

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [December 21, 2019, 12:35am UTC](https://forum.wixstudio.com/t/adding-values-from-database-in-query/31822/3 "2019-12-21T00:35:30Z")

</div>

@givemeawhisky I have, thank you. I have been toying with them and have managed to get the array to the console but can’t get the data to populate the ratings display… the code is part of another query that populates the repeater but I need to query a separate reviews database for the ratings.

Any ideas?

Field keys are all good

```javascript
wixData.query('Review-Stats')
.eq('id', ID)
.find()
.then((item)=>{
let avgRating = (Math.round(item.rating * 10 / item.count) / 10);
$w('#ratingsDisplay').rating = avgRating;
$w('#ratingsDisplay').numRatings = item.count
})

```

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/4/94fedd1783786979f1e72f46415058106f9322a8.jpeg)
