//this is short hand not actual code please
var = trainNum = 0;
// on button click
trainNum++;
// I can't figure out the format to put in so that firebase treats trainNum as the variable and not a string.
database.ref(Trains/**I WANT THIS TO EQUAL THE trainNum as it increments **).push({
});
//Train number is being stored in database I don't know if this will effect outcome.
Asked
Active
Viewed 29 times
0

ReyAnthonyRenacia
- 17,219
- 5
- 37
- 56

T. Stevens
- 5
- 1
- 3
1 Answers
0
You have to get the trainNum from database, and not set it to 0.
Im not sure if that was your question?

Muhaki
- 140
- 3
- 15
-
Sorry not quite don't the format so that firebase will treat trainNum as the variable and not treat it as a string. – T. Stevens Nov 22 '17 at 19:43
-
It shouldn't treat it as string. You cant increment string. – Muhaki Nov 22 '17 at 19:47
-
If its a string, you should convert it into an int with: var trainInt = parseInt(trainNum); trainInt++; – Muhaki Nov 22 '17 at 19:48
-
Ahh yea, thats right. But you still have to convert it to int, so you can increment the value. – Muhaki Nov 22 '17 at 19:59
-
When you type it into the ref() function for firebase, firebase treats it as a string when saving assigning it as the path. example of firebase database Trian ----TrainNum ------data ----TrainNum What I want to be Train ----1 ------data ----2 ------data – T. Stevens Nov 22 '17 at 20:00
-
Could u try `database.ref(Trains/${trainNum}).push({})` ? – Muhaki Nov 22 '17 at 20:18
-
it would be database.ref("train/" + trainNumber) – T. Stevens Nov 27 '17 at 22:55