0
function CalculateCuts(query, rank) {
    // query = a user input variable, rank = data the program knowns about the user
    let cut;
    const sql = `SELECT ${query} FROM spartan.cuts WHERE id = ${rank};`;
    con.query(sql, function(err, result) {
        if (err) throw err;
        cut = result[0][query];
    });
    return cut;
}

This function keeps returning as undefined. I've done some digging and I've come to the conclusion that it is due to my function returning before cut is assigned to result[0][query], but I've been unable to successfully implement a solution. I've seen some examples with callbacks and promises, but none that used node.js syntax and I had a bit of trouble following them.

0 Answers0