![](/img/trans.png)
[英]How to retrieve all values of a particular key in Firebase real time database?
[英]Retrieve attendance from firebase real time database
下面是我的firebase
結構。 我想檢索一個班級(從spinner
選擇)和一個主題(從spinner選擇)的出勤率。 我不想從firebase
檢索數據。 我想要的是每個學科中每個學生的禮物和缺席的數量。 請檢查我想要的圖像。
我想要這種結果。
"attendance":{
"01-01-19":{
"BSCS 1st_A":{
"c++":{
"std1":{
"attendance":"absent",
"id":"std1"
},
"std12":{
"attendance":"present",
"id":"std12"
},
"std2":{
"attendance":"present",
"id":"std2"
},
"std3":{
"attendance":"present",
"id":"std3"
},
"std4":{
"attendance":"absent",
"id":"std4"
}
},
"software engineering":{
"std1":{
"attendance":"present",
"id":"std1"
},
"std12":{
"attendance":"present",
"id":"std12"
},
"std2":{
"attendance":"present",
"id":"std2"
},
"std3":{
"attendance":"absent",
"id":"std3"
},
"std4":{
"attendance":"absent",
"id":"std4"
}
}
}
},
"05-01-19":{
"BSCS 1st_A":{
"calculus":{
"std1":{
"attendance":"present",
"id":"std1"
},
"std12":{
"attendance":"present",
"id":"std12"
},
"std2":{
"attendance":"present",
"id":"std2"
},
"std3":{
"attendance":"absent",
"id":"std3"
},
"std4":{
"attendance":"present",
"id":"std4"
}
}
}
}
您可以像這樣查詢firebase數據庫:
final DatabaseReference dinosaursRef;
dinosaursRef.child("01-01-19").child("BSCS 1st_A").child("c++").whereEqualTo("attendance", "present")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
QuerySnapshot querySnapshot = task.getResult();
int totalPresent= querySnapshot.size();
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
此代碼段將為您presents
BSCS 1st_A
和c++
類中的presents
數量。 你可以根據你的需要讓其他修改它presents
, absent
S和classes
。
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.