so I was trying to use a while loop to iterate through an array. I have succesfully gotten the sql connection to print a result using code without the while loop, so I know for a fact that the query works, it just doesn't work when in a while loop.
var sql = "SELECT algorithm FROM algorithms WHERE AlgorithmName = " + con.escape(PLLNames[0]);
con.query(sql, function (err, result) {
console.log("Sup")
if (err) throw err;
console.log("Result: " + result);
x+=1;
console.log(x)
});
res.render("PLL", {
algorithmTest: result,
});
Using something like this works fine, but when I edit this to have my loop, the code breaks. I know it's not performing the query because it's not logging the result and it's also not giving an error. For some reason the code doesn't even try to perform the query. This is what I tried to make work
x = 0;
while (x < 20) {
var sql = "SELECT algorithm FROM algorithms WHERE AlgorithmName = " + con.escape(PLLNames[0]);
con.query(sql, function (err, result) {
console.log("Sup")
if (err) throw err;
console.log("Result: " + result);
x+=1;
console.log(x)
});
};
res.render("PLL", {
algorithmTest: result,
});
Does anyone know why this might be happening?