The code snippet provided is causing an issue where `items.push` is not functioning correctly within the `if` statement. Interestingly, if you uncomment the line just before the closing brace `}`, then `items.push` works as intended.
for (i = 0; i < len; i += 1) {
row = resultexpense.rows.item(i);
t.executeSql('SELECT * FROM expensepayments WHERE Barcode = ?',
[row.barcode],
function(t, resultpaid) {
var myrowpaid,
myrowpaidlen;
myrowpaidlen = resultpaid.rows.length;
alert(myrowpaidlen); // alerts 1
if (myrowpaidlen > 0){
myrowpaid = resultpaid.rows.item(0);
alert(row.amount); // alerts 90
alert(myrowpaid.Amount); // alerts 50
if (row.amount > myrowpaid.Amount){
alert(row.amount - myrowpaid.Amount); // alerts 40
items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}
} else {
items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}
});
// items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}