0

From last few days, I'm unable to find the solution of this Condition of using AND parameter in the Query

Example SQL QUERY `"SELECT * FROM `NotesMe` WHERE `Uid`='randomUid' AND Pin='Yep'"`

So I was unable to filter my database in firebase with Multiple Conditions Eg. WHERE AND

I'm working with the Firbase PHP SDK v6

I tried to filter the data with the as per the firebase filter documentation but i was only able to filter with a single condition

$data = $database->getReference($ref)->orderByChild('Uid')->equalTo($uid)->getValue();

Above data Varible only returns the value in order to UID only

enter image description here

So I want filter that vaules with multiple Condition like Where UID AND PIN

1 Answer 1

0

So After searching a lot, I thought that should i make my own filter for this,

so what as I know that the below $data variable is returns an filtered array with single condition of OrderByChild

$data = $database->getReference($ref)->orderByChild('Uid')->equalTo($uid)->getValue();

So I decided ti filter that array again with a PHP array filter

$array = $data; // $data contains is already filtered array 
$filter_name ='Pin'; // another conditions
$filter_value ='yep';
$expected = array_filter($array, function($el) use ($filter_value, $filter_name) {
    return ($el[$filter_name] >= $filter_value);

});

and finally it works now I'm able to use multiple conditions in firebase databse too with PHP

$expected contains the new re-filtered array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.