【问题标题】:Filter Firebase database with Multiple Conditions PHP使用多个条件 PHP 过滤 Firebase 数据库
【发布时间】:2022-07-22 03:27:24
【问题描述】:

从最近几天开始,我无法找到在查询中使用 AND 参数的条件的解决方案

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

所以我无法使用多个条件过滤我的数据库在 firebase 中,例如。在哪里和

I'm working with the Firbase PHP SDK v6

我尝试按照 firebase 过滤器文档过滤数据,但我只能用一个条件过滤

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

以上数据变量只返回值,以UID

所以我想要具有多个条件的过滤器,例如Where UID AND PIN

【问题讨论】:

    标签: php arrays firebase firebase-realtime-database


    【解决方案1】:

    所以在搜索了很多之后,我认为我应该为此制作自己的过滤器,

    据我所知,下面的$data 变量返回一个过滤后的数组,其单一条件为OrderByChild

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

    所以我决定使用PHP 数组过滤器再次过滤该数组

    $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);
    
    });
    

    最后它现在可以工作了,我也可以使用 PHP 在 firebase 数据库中使用多个条件

    $expected 包含新的重新过滤数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      • 2011-07-11
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-02
      相关资源
      最近更新 更多