0
And I’m doing a query in a Sqlite database and wanted the result to be stored in a javascript variable so I can work with these results in the rest of the code.
I’m doing like this:
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);
But this code does not work.. only if I put the alert
within the loop
that 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);
}
I need these variables to use at the end of my html code Does anyone have any suggestions on how I’m going to do this?
If you put Alert OUT of the for(), it will only display the last value returned from the bank.
– PauloHDSousa
In the case of this query only displays a result even, but if I put off the
db.transaction(function(tx) {
doesn’t show anything at all– Dani Carla
What do you want to do? Want to work with ALL the records that come back?
– PauloHDSousa
Only one record will come back... I want to work only with him
– Dani Carla
Try thus Results.rows.item(0). name;
– PauloHDSousa
Gave the same error.. on the console appeared:
Uncaught ReferenceError: var_name is not defined
– Dani Carla
Now I understand, CREATE the var_name and var_country variables Out of FOR
– PauloHDSousa
I did as you said. (I actually had already done) I tried to create them out of for.. but it also didn’t work out.... :(
– Dani Carla
Maybe @Marcelo Bonifazio can help you.
– PauloHDSousa