Guidance in displaying rating from database

I have a review system for wix store that works great on the product page,would like to display the total number of reviews and the aggregate of the stars in a star rating display on a different page,i am trying to reuse the code that works great on the product page but not on a separate page,any guidance?Thank you

ERROR → however the database fields are correct
Wix code SDK error: The rating parameter that is passed to the rating method cannot be set to the value NaN. It must be of type number. Line 20
Wix code SDK Warning: The numRatings parameter that is passed to the numRatings method cannot be set to null or undefined. Line 21

/$w.onReady(function () {
/
$w(‘#dataset2’).setFilter(wixData.filter(‘reviews’)); //dataset with the reviews
loadStatistics();

// Load the current product’s statistics.
function loadStatistics() {

const stats = wixData.get('review-stats'); //dataset with the statistic reviews for each product 
// If statistics data for the product was found: 
if (stats) {  
    // Compute the product's average rating by dividing the total points by the number of ratings. 
    let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10);  
    // Compute the percentage of reviewers that recommend the product. 
    let ratings = $w('#generalRatings');//rating display  
    // Set the ratings element's average rating to the value calculated above.  
    ratings.rating = avgRating; //line20 
    // Set the ratings element's number of ratings to the count value from the statistics data. 
    ratings.numRatings = stats.count;  //line21 
    // Set the text for the recommended percentage element. 

}
}
});

Line 20
NaN basically stands for not a number, you need to be using a number (has to be a whole number only) which the javascript in Wix code will recognise as an actual number.
https://www.w3schools.com/jsref/jsref_number_nan.asp

Line 21
Your code is not receiving a number in return when it looks for the numRatings value.

As for code itself, the Wix tutorial for ratings and reviews in Wix Stores is designed to be shown for each product on each product’s own page and not elsewhere.
https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site

The same with the ratings and review tutorial for a normal Wix page, it is still only designed to be shown all on the same page.

HI @givemeawhisky
Thank you for help.
I was aware what the error wording means but not sure why as the database fields are number values,i have tried adapting the tutorial to don’t be product related obviously i didn’t managed :smiley:

Can you please tell me what do you mean by this?
" The same with the ratings and review tutorial for a normal Wix page, it is still only designed to be shown all on the same page. " → so the rating input and rating display has to be on the same page

Is there a way to display the total number of ratings and the total star rating received in the wix store for all the products,in the footer of the website?If yes what would be the best approach?

I have read about the aggregate in the wix api,and tried to solve this with a different approach.
Ran a query on the database
Got the total count of reviews
console returned a correct number but can’t manage to display this number in the ratings display

@bmelida99 hey - did you ever receive an answer to this question? I’ve been searching for an hour now…

@marlenasfeather An answer to what question? Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines .

This is an old post and is being closed.