Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
How can i use/send the information inside an array from one block to another block js

So my issue is this I have a SQL query that push its result into an array

connection.query('SELECT id FROM parada WHERE ubi_calle_id =? ',[calleID], async (err,resultid)=>{

            for (i =0; i < resultid.length; i++){
                ParIds[ParIds.length] = {
                  id: resultid[i].id  
                }           
            }
            
            for(i=0; i < ParIds.length; i++){
                parID =  ParIds[i].id
                
                //console.log(parID, "par id")
                
                connection.query(`SELECT parada.id , trayecto.recorrido_id, recorrido.linea_id, lineas.name AS nombre_linea, lineas.ramal FROM (((parada INNER JOIN trayecto ON parada.id= trayecto.parada_id) INNER JOIN recorrido ON trayecto.recorrido_id = recorrido.id)INNER JOIN lineas ON recorrido.linea_id= lineas.id) WHERE parada.id = ${parID} `, async (err,resultLineas)=>{
                    if (err) throw err;
                    
                    //console.table(resultLineas)
                    lineas.push(resultLineas);
                    console.log(lineas, "esto")
                    
        
                });
                
                
            } 
        })

So each element of the array lineas is an array of the result of the second query and it show something like this lineas = [[1,2,3],[1,4],[3]]

But now I have another SQL query that brigs me another result

connection.query('SELECT parada.*, calle.name AS ubi1, c.name as ubi2 FROM ((parada INNER JOIN calle ON parada.ubi_calle_id = calle.id)INNER JOIN calle c ON parada.ubi_casi = c.id) WHERE ubi_calle_id =? ',[calleID], async (err,result)=>{ });
      

Inside of this second SQL query "block" I need to use or somehow bring the array "lineas" that I got from the first SQL query but I can't do it, If I try to use it inside the second SQL query the array is always empty "console.log (lineas) will show []. So how can I save that array from the first SQL query in way where console.log(lineas) inside the second SQL query will also bring me lineas= [[1,2,3],[1,4],[3]]

PS : I'm so sorry for my bad english I tried my best. PS2 : The only way I can somehow use the data from lineas inside the second SQL query is if I put the second SQL query inside the first 1 which is not an option since it will be inside the for loop.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!