I am executing a mysql query inside a for loop, this loop is in callback function but when i do console.log(i), it shows me 3 three times. below is the code. I am using async.parallel, I am only posting the code which is having the problem. Also res is returning fine but obj is showing the third record three times, instead it has to show obj1 data, obj2 data, obj3 data. console.log(i) is the example response.
function(user,callback){
for(var i = 0; i < user.length ; i++) {
var obj = user[i];
mySQLConn.mySQLDBConnection.query('select id,name from table where type = ?',[obj.id],function(err,res){
console.log(i); //This shows 3 three times
obj.type = res;
userJSONArray.push(obj);
})
}
}
What I want it should print 1,2,3 instead of 3,3,3. Any help is really much appreciated.