0

So the problem is im cant wrap my head around in node.js code execution, here is the code im using atm

app.get('/cetvrti',(req,res,next)=>{
data=[];
for(i=0;i<12;i++){

    let Qf=db.query("SELECT Broj FROM tblPolisa WHERE ZastupnikID='"+IdZastupnik+"' AND DatumIzdavanja BETWEEN '"+datum[i].str+"' AND '"+datum[i].end+"';",(err,result,field)=>{
        
        console.log(result+'result prvi');
        if(err)throw err;
        else{
            console.log('pocetak else loopa');
            if(result.length<1)data.push(0);
            else data.push(result.length);
            
            console.log(data);

            
        

        }
    })
}
function rendering(d){
    console.log('ovo je console.log prije renderinga'+d);
    res.render('cetvrti-final',{zastupnik:d});
}
rendering(data);

})

(the datum[i].str and datum[i].end is just some array i use to filter trough like months in a year so yeah) and the like problematic part for me here is that the console.log('ovo je console.log prije renderinga'+d); is executing before the for loop and all the console.logs there, so by my thinking its rendering as well before its going throughout the loop, and thats why i have no data displayed in zastupnik/on page when it loads, it still executes it is just that i think it like first rendering without data then getting the data which is pointless cuz i already rendered my page... Any advice or tips...as i said im new, i dont know how all these shenanigans work :D .

0 Answers0