Hi I try to select data from 2 tables.
I want to select from bill the flatname where bill flatdescription is equal to buildingflats flatname.
Here is my code
t.executeSql('SELECT * FROM buildingflats WHERE buildingcode = ? ORDER BY flatname ASC',[buildingcode], function(t, resultflatcomment) {
var j,
lenflatcomments = resultflatcomment.rows.length,
rowflatcomments,
row;
if (lenflatcomments > 0 ) {
for (j = 0; j < lenflatcomments; j += 1) {
rowflatcomments = resultflatcomment.rows.item(j);
alert(rowflatcomments.flatname);
t.executeSql('SELECT DISTINCT flatdescription, flatname, buildingcode FROM bill WHERE buildingcode = ? AND flatdescription = ?',[buildingcode, rowflatcomments.flatname], function(t, resultflat) {
var len = resultflat.rows.length;
if (len > 0) {
row = resultflat.rows.item(0);
//alert(row.flatdescription);
//alert(row.flatname);
$('#opt2').append('<option value="' + row.flatdescription + '">' + row.flatdescription + '...' + row.flatname + '</option>');
} else {
//alert(rowflatcomments.flatname);
$('#opt2').append('<option value="' + rowflatcomments.flatname + '">' + rowflatcomments.flatname + '</option>');
}
$("#opt2").selectmenu('refresh');
});
}
}
});
The problem is that if len is equal to zero I receive always the last buildingflats flatname.
Where am I wrong??
Aucun commentaire:
Enregistrer un commentaire