Lemuel Ogbunude
Lemuel Ogbunude

Reputation: 184

Firebase get Child Value after Query

So I have a firebase structure like one below: enter image description here

I want to get the 'Shop' of a person whose 'Phone' is a particular value.

Query address=databaseReference.child("Users").orderByChild("Phone").equalTo(phone);

So the Query above is used, but...I do not know how to access the child of the result. After getting the query above, assuming the variable phone was 1234567890 how do I get the value of the Shop or Email of this particular user. I have tried different methods but I think I am not getting something right. :/

I think once I see a working example I would be able to apply it on mine.

Upvotes: 1

Views: 649

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

DatabaseReference address= 
database.getReference("Users").orderByChild("Phone").equalto(phone);

address.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
for(DataSnapshot data: dataSnapshot.getChildren()) {
String value=data.child("Shop").getValue().toString();
}
}

 @Override
    public void onCancelled(DatabaseError databaseError) {
    }
});

You are querying on Users, then doing a condition orderByChild("Phone").equalto(phone). So, its like you are doing where Phone=value_phone

Upvotes: 1

Related Questions