when the variable form_loop (with for loop) executes, it only executes the last element of its array (the 'f14' one), i tried console.log the queries and will output like this :
for the first query (which is correct),
"SELECT * FROM f11 where eacode='4'"
"SELECT * FROM f12 where eacode='4'"
"SELECT * FROM f13 where eacode='4'"
"SELECT * FROM f14 where eacode='4'"
for the second query (which is wrong),
"INSERT IGNORE INTO f14 (...) VALUES(...);"
"INSERT IGNORE INTO f14 (...) VALUES(...);"
"INSERT IGNORE INTO f14 (...) VALUES(...);"
"INSERT IGNORE INTO f14 (...) VALUES(...);"
in that, it only executes the last element of array and i want an output like this in the second query...
"INSERT IGNORE INTO f11 (...) VALUES(...);"
"INSERT IGNORE INTO f12 (...) VALUES(...);"
"INSERT IGNORE INTO f13 (...) VALUES(...);"
"INSERT IGNORE INTO f14 (...) VALUES(...);"
var col = [];
var values = [];
var sql = "";
var rn = 0;
var forms = ['f11', 'f12', 'f13', 'f14'];
var form_loop;
for (var f in forms) {
  form_loop = forms[f];
  db2.all("SELECT * FROM " + form_loop + " where eacode='" + eacode + "'", function(err, rows) {
      for (var i = 0; i < rows.length; i++) {
        for (var k in rows[i]) {
          col.push(k);
          values.push(rows[i][k]);
        }
      }
      sql = "INSERT IGNORE INTO " + form_loop + " (" + col.join(",") + ") VALUES('" + values.join("','") + "');";
      connection.query(sql, function(err, rows) {
        if (err) console.log("Error number : " + err);
        rn++;
      });
      col = [];
      values = [];
    }
  });
} 
    