I have nested functions which should not block the I/O.
for(let i = 1; i < category_amount;i++){
pool.query('SELECT COUNT(1) FROM threads_mphp WHERE category = ?',i,function(error, results1, fields) {
console.log(i);
pool.query('UPDATE category SET posts=? where category=?',[results1[0]['COUNT(1)'],i],function() {
console.log(i);
});
});
}
Both queries work with the same index i. I cannot use let for such purposes. The console.logs doesn't output as expected two same numbers in a row. How can I solve this problem?