Hi,
I have a mysql database table called MASTER which have around 10 columns - with the field ‘TS’ being a primary key. I want to write a function wherein three fields - TS, MWP & LTP - from every row are retrieved from the table and stored as a variable “tmpAnalysis” - based on which some rules are run.
The below code is generating only the first row from the MASTER table - I want it to run for each row. What should I be doing?
Thanks
funcE = function (MasterGet) {
var countCheckRule = 0;
var countCheckedRule = 0;
var tmpAnalysis = {};
rules.rule12(tmpAnalysis, function (_tmpAnalysis) {
tmpAnalysis = _tmpAnalysis;
});
news.analysis = tmpAnalysis;
connection.query('SELECT * FROM MASTER', function selectCb(error, results, fields) {
if (error) {
console.log('402-GetData Error: ' + error.message);
return;
}
if (results.length > 0) {
results.forEach(function (value) {
var firstResult = results[0];
console.log('403-funcE from firstresult TS: ' + firstResult['TS'] + 'MWP: ' + firstResult['MWP'] + 'LTP: ' + firstResult['LTP']);
news.Master = firstResult;
io.emit('news', news);
var TS = firstResult['TS'];
var MWP = firstResult['MWP'];
var LTP = firstResult['LTP'];
rules.checRules(firstResult, myhttp, function (rules_res) {
console.log('404-Rules check triggered');
firstResult.rules = rules_res;
})
});
}
});
countCheckRule++;
console.log('405-funcE ends - funcA called');
funcA();
};