function GetMe(id) {
DB.transaction(
function (transaction) {
transaction.executeSql("SELECT * FROM users WHERE id = ?", [id], function (transaction, results) {
if(results.rows.length > 0) {
var row = results.rows.item(0);
return row.name;
}
}, errorHandler);
}
);
}
alert(GetMe(1)); // id 5 exists in users table and alert shows empty
the above code dosent work so i tried the below codes
function GetMe(id) {
var retval;
DB.transaction(
function (transaction) {
transaction.executeSql("SELECT * FROM users WHERE id = ?", [id], function (transaction, results) {
if(results.rows.length > 0) {
var row = results.rows.item(0);
retval = row.name;
//alert('IN ' + retval); //works
}
}, errorHandler);
}
);
//alert('OUT ' + retval); // undefined
return retval; // undefined
}
alert(GetMe(1)); // undefined
the above code should work fine but it dosent i dont know whats wrong with it , i tried almost everything
can someone tell me whats wrong and help me fix this thanks :)