0

I'm trying to transfer the results of my query in Sqlite to variables of the Javascript, but it does not work!

My code is:

db.transaction(function(tx) {
var ide = 1;
tx.executeSql('SELECT * FROM tab_users', [ide], function (tx, results) {
  var len = results.rows.length, i;
  for (i = 0; i < len; i++) {
    var_name = results.rows.item(i).name;
    var_country = results.rows.item(i).country;
    
  }
});
});
alert ("Name is " + var_name + " and country is " + var_country);

This code only works if I put the ALERT inside the loop . This way:

for (i = 0; i < len; i++) {
    var_name = results.rows.item(i).name;
    var_country = results.rows.item(i).country;
    alert ("Name is " + var_name + " and country is " + var_country);
    
  }

But I need to use these variables in the rest of my code.

Any suggestion?

EDIT: This question not been asked before: I'm not using jQuery

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dani Carla
  • 65
  • 6

0 Answers0