mercredi 28 octobre 2015

Qqlite: results in variables javascript

I trying transfer the results of my query in Sqlite to variables of the Javascript, but 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?

Aucun commentaire:

Enregistrer un commentaire