I have a function that returns me a persons username from my database. I then want to use that returned value to query another table, and return the data from that. what I set up was this:
var select = "select * from USERS WHERE ASSIGNED_TRAINER = ?"
console.log("INSDE getClientList");
mysqlconn.connect(function(err) {
if (err) {
console.error('Database connection failed: ' + err.stack);
return;
}
mysqlconn.query(select, [req.session.username], function(err, rows) {
if (err) {
console.log(err);
} else {
for (var i = 0; i < rows.length; i++) {
// need to query the database again, using this value: rows[i].USERNAME
console.log(rows[i].USERNAME)
}
getNumOfSessionForTrainerClientList(req, res, rows[i])
}
mysqlconn.end();
})
})
then I created this function:
function getNumOfSessionForTrainerClientList(req, res, rows) {
var getNumOfSessionForTrainerClientList = "select * from SCHEDULE WHERE CLIENT_USERNAME = ? AND ASSIGNED_TRAINER = ?"
mysqlconn.connect(function(err) {
if (err) {
console.error('Database connection failed: ' + err.stack);
return;
}
mysqlconn.query(getNumOfSessionForTrainerClientList, [rows.USERNAME, req.session.username], function(err, sessionData) {
if (err) {
console.log(err);
} else {
//go to checkIfUserPaid
console.log("Lenght or rows: " + sessionData.length);
for (var x = 0; x < sessionData.length; x++) {
console.log(sessionData[x])
}
}
mysqlconn.end();
})
})
}
however, because there are going to be up to 25 usernames, then i need to loop through the results and query the schedule table. how can I do this?