0

I have 2 functions, first one is kind of main which calls others to get ratings and calculate new ratings from DB. The problem I have is that getRatings function always returns NaN on first call. But each time after that it works but it has data from call before that. I have no idea how that happens.

function processVote(vote, options, picnum){
    
    var ratings =  getRatings(options, picnum);
    console.log("Ratings:" + ratings)
    processPoints(vote, options, ratings, picnum);

}



function getRatings(options, picnum){

    for (let i = 0; i < options.length; i++) {
        con.query("SELECT pic" + picnum + " FROM picsdata WHERE fullname = '" + options[i] + "'" ,function(err, result, fields) {
            if (err) throw err;
            rating[i] = (result[0].pic1);
        })}
    
    return rating;
}
BokyS
  • 1

0 Answers0