0

I would like with my array works outside of my for loop but my array is empty:

let dataSitesIndex = [];
            for(let i = 1; i <= dataMainIndexLength; i++){
                pdo.query("SELECT * FROM subsites WHERE main = ?",[i] , function(err, result, fields) {
                    dataSitesIndex[i] = result;
                    console.log(result);
                })
            }
let dataLength = async function(){
    try {
        //Durchsuchen der Nachrichtenseite, speichern der MainID
        pdo.query(`SELECT * FROM mainsites`, function(err, result, fields) {
            let results = result;
            let resultsLength = results.length;


            //MainID
            let dataIndexMainId = [];
            for(let index = 0; index < resultsLength; index++){
                dataIndexMainId[index] = results[index]["id"];
            }


            let dataMainIndexLength = dataIndexMainId.length;

            let dataSitesIndex = [];
            for(let i = 1; i <= dataMainIndexLength; i++){
                pdo.query("SELECT * FROM subsites WHERE main = ?",[i] , function(err, result, fields) {
                    dataSitesIndex[i] = result;
                    console.log(result);
                })
            }


        })
    } catch(error) {
        console.log(error)
    }
}
3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.