0

I have the following problem. I have a function that fetches the result from 6 different MySQL tables with different columns and puts it into an array. The problem is the query runs through, all rows are found but not transferred to the target array. This remains always empty. I don't know for the life of me what the reason is. For more than 3 hours now I am on the hose.

Attached is my code:

const working_areas = [
    'instandsetzung',
    'strabasofomld3',
    'inspektion',
    'austausch',
    'abbruch',
    'deta'
]

var userWorkAll = function getUserWorkAll(email_decode) {
    console.log(email_decode);
    var newRow = [];
    working_areas.forEach(function (area) {
        connection.query('SELECT * FROM ' + area + ' WHERE ersteller = ?', [email_decode], (err, rows, fields) => {
            if (!err) {
                newRow.push(rows);
            } else {
                console.log(err);
            }
        });
    });
    //console.log(newRow);
    return(newRow);
}

I hope for some final thoughts. Thanks <3

I tried to check if anywhere in the SQL Query mistakes are happening, printing out debug data. Everything works till there correctly.

Clusterzx
  • 1
  • 2
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) You fill `newRow` asynchronously in `connection.query`, but return it synchronously, before it is filled. – Heiko Theißen Nov 01 '22 at 12:50
  • @HeikoTheißen Thanks for the advice, I really appreciate it. But due to my lack of knowledge I run into another problem there. The promise function wont work just like that with an exported module? Or maybe I really don't get it. I will research more on your tip. I call back later here. – Clusterzx Nov 01 '22 at 13:47

0 Answers0