Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mahmoudtrageh's avatar

I want to use orderBy throw this array ?

this code responsible for retrieving data and make a pagination from firestore

$limit = 10;

$url = 'm-url'&pageSize='.$limit.'&pageToken='.$nextPageToken;

$json = json_decode(file_get_contents($url), true);

$users = $json['documents'];

I want to use orderBy and get the data on basis of created_at field ?

0 likes
3 replies
mahmoudtrageh's avatar

tnx so much.. but it will sort only 10 results (the limit value) .. can you help me to make it sort all results ?

squiaios's avatar

First, remove your URL, because with the key, everyone can access your data.

Instead, insert a sample of the data, like

{
  "documents": [
    {
      "name": "......",
      "fields": {
        "created_at": {
          "timestampValue": "2020-08-27T14:41:40.508Z"
        }
      },
      "createTime": "2020-08-27T14:41:40.644088Z",
      "updateTime": "2020-09-08T10:48:50.207951Z"
    },
    {
      "name": "......",
      "fields": {
        "created_at": {
          "timestampValue": "2020-08-27T14:41:40.508Z"
        }
      },
      "createTime": "2020-08-27T14:41:40.644088Z",
      "updateTime": "2020-09-08T10:48:50.207951Z"
    },
    {
      "name": "......",
      "fields": {
        "created_at": {
          "timestampValue": "2020-08-27T14:41:40.508Z"
        }
      },
      "createTime": "2020-08-27T14:41:40.644088Z",
      "updateTime": "2020-09-08T10:48:50.207951Z"
    }
  ]
}

But what you want is to sort all tour results, so you have to check google api to check if exists an option to sort the result. If this option does not exists, put the results into a collection, then sort the collection (report to @pedroroccon message)

1 like

Please or to participate in this conversation.