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()]);