Answer the question
In order to leave comments, you need to log in
How to make one mysql query wait for another in Node js?
The posids array should store the IDs of the newly created rows in the MYSQL table and
then transfer them to another table, but it turns out that both queries are processed first
, and only then this array is filled, and the column remains empty. Please tell me how to do it better
while (i < rowcount) {
pool.query(`INSERT INTO positions(len,count,sqr,cost) VALUES(?,?,?,?)`, [request.body['inputlen' + rowids[i]],
request.body['inputcount' + rowids[i]], request.body['sqrr' + rowids[i]], request.body['cost' + rowids[i]]
], function(error, results, fields) {
posids.push(results.insertId);
console.log(posids);
})
i++;
}
if (wave && color && thickness && fthickness && date) {
console.log('first' + posids);
pool.query(`INSERT INTO orders(wavetype,thick,fthick,color,createdate,readydate,positions) VALUES(?,?,?,?,?,?,?)`,
[wave, thickness, fthickness, color, currentdate, date, posids.toString()], function(error, results, fields) {
console.log(rowcount, rowids);
response.redirect('/home');
response.end();
})
} else {
response.send('Введены не все данные');
response.end();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question