Skip to content Skip to sidebar Skip to footer

How Can I Retrieve Values From Firebase Database Based On Email Entered By User In Text Field?

I am working on Firebase database. How can I retrieve values from database based on email entered by user in text field. Below is my database structure. Kindly help. Here is my co

Solution 1:

You have:

 Registration
       UserRegistration
               12
                pushid
                  key:values
                  email:emailvalue

To retrieve values always you have to go from top to bottom, so you cannot skip any node.

Only orderByChild(..) query can skip one node (which means you use this query if you want to get children that are not direct children)

Try this:

DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Registration").child("UserRegistration").child("12");
ref.orderByChild("email").equalTo(emailenteredbyuser).addListenerForSingleValueEvent(newValueEventListener() {
        @OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
     for (DataSnapshot datas : dataSnapshot.getChildren()) { 
           String email=datas.child("email").getValue().toString();

          }
        }
        @OverridepublicvoidonCancelled(FirebaseError firebaseError) {

       }

 });

As you can see in the above, the reference passes through every node until node 12.

Then you use this orderByChild("email").equalTo(emailenteredbyuser) to get the email entered by the user.

for (DataSnapshot datas : dataSnapshot.getChildren()) this for loop the datas iterates in inside the direct children of 12 which is the pushid that way you do not need to retrieve the pushid to get the values inside of it.

Solution 2:

Try this! here I am running for each loop to get each child.

Ref.child("UserRegistration").child("email").addValueEventListener(newValueEventListener() {
            @OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {

                for (DataSnapshotsnapshot:dataSnapshot.getChildren()){
                    user_reg user=dataSnapshot.getValue(user_reg.class);
                    System.out.println(user.email);
                }
            }

            @OverridepublicvoidonCancelled(DatabaseError databaseError) {

            }
        });

Post a Comment for "How Can I Retrieve Values From Firebase Database Based On Email Entered By User In Text Field?"