I'm trying to make a simple table that is populated by a table I have made in FireBase. I am new to FireBase, I normally work in mySQL and usea combination of php and SQL to pull from the database. My current JSON structure is {
"board1" : {
"c0" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c1" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c2" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c3" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c4" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c5" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c6" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0",
"c7" : "0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0"
}
}
And I'm looking for a way to retrieve the value of specific cells for example c3 and the third item in the array and store it as a javascript variable. Every example I have found on FireBase is complex and broken up. Thanks for your help!
var database = firebase.database();
var i;
var j;
for (i = 0; i < 7; i++) {
for (j = 0; j < 6; j++) {
var R = i.toString();
var C = j.toString();
var id = C.concat("",R);
var col = "c"+R
var x = piece(i,j);
document.getElementById(id).innerHTML = x;
}
function piece(i,j) {
var C = j.toString();
var col = "c"+C
return database.ref('board1/'col).once('value').then(function(snapshot) {
console.log(snapshot.val());
var piece = snapshot.val()[i];
console.log(piece);
});
});
}
}