I have this code in PHP and it works excellent, I am passing it to node (javascript) but it is giving me problems, it does not expect to terninate the conditionals and continues with the process, it gives me as a result the empty variable.
var variable = "";
if (typeof req.body.princp !== 'undefined') {
if (iduser == idperprincp ) {
var sqlfav = `SELECT * FROM tblfavo WHERE idusr = '${iduser }' ORDER BY id DESC`;
mysqlcon.query(sqlfav, function (err, refavsql) {
if (err) throw err;
if (refavsql.length > 0) {
variable = "restul 1"
} else {
variable = "restul 2"
}
})
} else {
variable = "restul 3"
}
} else {
variable = "restul 4"
}
console.log(variable) // Result empty..
because it always returns the bariable empty, the same code in PHP if it works well, apparently, in node (javascript) first prints the variable and then does everything within the conditional, how do you solve that problem?, thank you very much