I have a question about Cordova and the Cordova-Sqlite-Storage Plugin.
I want to select two tables, but the second selection is in the loop of the first. But it is not synchronized.
The code isn't productive or anything, it's purposely easy to understand.
document.addEventListener('deviceready', function(){
var rooms_id_arr = [];
db.transaction(function(tx){
tx.executeSql('SELECT id FROM rooms', [], function(tx, result_rooms){
for(var r = 0; r < result_rooms.rows.length; r++){
rooms_id_arr.push(result_rooms.rows.item(r).id);
}
}, function(tx, error) {
alert("ERROR A: " + error.message);
});
for(var r = 0; r < rooms_id_arr.length; r++){
tx.executeSql('SELECT id FROM regal WHERE roomid=?' , [rooms_id_arr[r]], function(tx, result_regal){
for(var rg = 0; rg < result_regal.rows.length; rg++){
alert("Room: " + r + " Regal: " + rg);
}
}, function(tx, error) {
alert("ERROR B: " + error.message);
});
}
});
});
First Table (rooms): id, name
Secound Table (regal): id, roomid (key from table rooms), name
Every room have more shelves. i know how joins work, i would like to know how to do it that way (for understand). How could this best be implemented? i have tried many options, but have not come to any result. Thank you very much for your answer.