I'm writing javascript code in node.js that is meant to loop through an array of data that I have scraped from the web. The purpose of the code is to:
1) Check the player table to see if that player's name exists in a record, and 2) If that player doesn't exist, add him to the database.
Here is my code:
for(i=1;i<data.length;i+=26){
var query = connection.query(
"SELECT * FROM player WHERE name = '"+data[i]+"'",function(err, result, fields) {
if (err) throw err;
if(result.length==0){
//var insertQuery = "INSERT INTO player (provider_id, team_id, position_id, name) VALUES (1, (SELECT id FROM team WHERE slug = '"+data[i+1]+"'),1,'"+data[i]+"');";
console.log(i);
}
});
}
Note that I commented out my INSERT query for testing purposes, but the player name is located in data[i] while the team name is in data[i+1].
To test, I am just printing i to the console, and every loop it prints out the max value of i, which is 3225. However, that console.log command is INSIDE the for loop, so shouldn't it print each value of i as it is incrimented?
Aucun commentaire:
Enregistrer un commentaire