I am trying to query, foreach id in an array, some data from the MySQL database. My for loop looks like the following
for(var i = 0; i < res.length; i++) {
var steamid = res[i].steamid;
db.query('SELECT `name` FROM `users` WHERE `steamid`=?', [steamid], function(err, rows) {
var player = {name: rows[i].name};
team.push(player);
});
}
But the problem is that the for loop continues before the query is finished and then the var i
is already increased by one or two.
Is there a way to check if the query has finished?