I am trying to iterate an dynamic array as input for select query. The select query is not firing for all array elements. I wrote select query in for loop, the problem is loop is firing first and the select query is performing only for last element of array. may be this due to asynchronous function. How can I resolve this, My code is as follows,
function sendCategoryDetailsNew(myLocation)
{
var myLocationcoordinates = new Array();
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
for (var i = 0; i < myLocation.length; i++)
{
var locationName = myLocation[i];
alert(locationName);
db.transaction(function (tx) {
tx.executeSql("select Coordinates from Locationlog WHERE Location = '"+locationName+"';", [], function (tx, res)
{
for (var i = 0; i < res.rows.length; i++)
{
alert("Location : "+locationName+ " Latlongs :"+ res.rows.item(i).Coordinates);
myLocationcoordinates[i] = res.rows.item(i).Coordinates;
}
});
});
}
}
Any suggestions,