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

90
Views
Reading from a database and adding that value to a variable

My problem is that I can read from a database, but when I try to add the value to a variable, it won't be saved and uses the original value when it was declarated. My question is that can I use the value from the database outside of the "con.query" and if yes how can I save it

here is the code:

con.connect(function (err) {
  if (err) throw err;
  //ez a resze megnezi hogy hany elem van az adatbazisban
  con.query("SELECT COUNT (id) FROM product", function (err, result, fields) {
    if (err) throw err;
    else{
    hossz=result
    console.log(result)
    }
    });
    //Ez meg fel kellene hogy toltse a mapot az adatokkal
  con.query("SELECT * FROM product", function (err, result, fields) {
    if (err) throw err;
    
      for(let i=0;i<2;i++){
        storeItems.set([i,{name:result[i].id,price:result[i].price}])
        console.log(result[i].name)
      }
      storeItems.set(result.id,result.price)
      console.log(result)
    });
  });
console.log(hossz)
console.log([...storeItems.entries()]);

enter image description here

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!