# How to filter/sort values on Firebase

**URL:** <https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036>\
**Category:** Questions about Thunkable X\
**Tags:** firebase, ios\
**Created:** [April 21, 2019, 6:19pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036 "2019-04-21T18:19:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![IWendling](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/iwendling/32/31718_2.png) [@IWendling](https://community.thunkable.com/u/IWendling)\
**Post date:** [April 21, 2019, 6:19pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/1 "2019-04-21T18:19:30Z")

</div>

Again with more and more doubts… 😫😫😫😫

My app and Firebase are working properly, and now I want the app to “filter” data from Firebase, more especifically from column BOX. So, if I say that I want to see box 1, I want the app to look in my database and only display those cells to me.

The structure of the DB is:

 ![Capturar1](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/b/cb01defbf5cdaafa372ee33b1c40c89aef47f3b8.jpeg)

In Thunkable I tried several ways, but none of them work… See my attempts below:

First attempt:  
 ![Capturar3](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/2/22a850aa82935a123648da0dc9047e659cf803de.jpeg)

Second attempt:  
 ![Capturar5](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/1/01279fc4ca23dd9478907a913bc11a6d049e6a65.jpeg)

Thank you once again!

---

<div class="post-metadata">

**Author:** ![Cian\_O\_Sullivan](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cian_o_sullivan/32/34494_2.png) [@Cian\_O\_Sullivan](https://community.thunkable.com/u/Cian_O_Sullivan)\
**Post date:** [April 22, 2019, 12:02am UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/2 "2019-04-22T00:02:58Z")

</div>

Well the first example looks good to me except for one problem. You are starting the list number at 1 when your database starts at 0

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/7/e7baac50230ae7abd14481fa59304e530549ed75.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/2/f27c56a1920e1ffc33cf444127f2b843e321c9fd.png)

Is the variable app sizeDB a number, and in a blue block?

Can you also setup a label for the error?

---

<div class="post-metadata">

**Author:** ![IWendling](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/iwendling/32/31718_2.png) [@IWendling](https://community.thunkable.com/u/IWendling)\
**Post date:** [April 22, 2019, 6:42am UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/3 "2019-04-22T06:42:01Z")

</div>

Hi, Cian!

Thank you for your reply. I changed the starting number of the list to 0 (my mistake!) and this variable “sizeDB” is a number I add manually in the global variable. I didn’t know how to code to return the size of my DB and this way I solved my problem temporarily.

Working with localDB was perfect for me, except that I couldn’t update the value. I changed my whole app to work with firebase, but now I struggle with simple things like filtering it.

The first exemple, when I want the app to store a VALUE if VALUE=0, it returns an empty list. But if I remove the IF statement (my filter), and ask the app to build the list, it runs perfectly and returns all items I have there.

![r1](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/c/fc34eab7cd12aa31191d950cb0b8bba0609cba7c.jpeg)  
(Don’t know why, but I have to ask the app to wait 1 second otherwise it returns repetitive itens)

Then if I ask it to display the error message, it crashes. No matter where the error is put (inside/outside the IF statement)  
 ![r2](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/2/3212ea3633858a2a9cafb51652794d3398a5c4db.jpeg)

---

<div class="post-metadata">

**Author:** ![Cian\_O\_Sullivan](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cian_o_sullivan/32/34494_2.png) [@Cian\_O\_Sullivan](https://community.thunkable.com/u/Cian_O_Sullivan)\
**Post date:** [April 22, 2019, 9:03am UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/4 "2019-04-22T09:03:21Z")

</div>

The error bug is strange.

With the first issue…

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fd8602df796ec950b58bbd549f97a837ef46318b.jpeg)

Are you setting that as an empty list at the begiing? How do you declare this value?

---

<div class="post-metadata">

**Author:** ![IWendling](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/iwendling/32/31718_2.png) [@IWendling](https://community.thunkable.com/u/IWendling)\
**Post date:** [April 22, 2019, 9:35am UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/5 "2019-04-22T09:35:37Z")

</div>

> [@Cian\_O\_Sullivan](#):
>
> setting that as an empty list at the begiing? How

I declare as an empty list.

 ![rq](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/f/1f2dc1a247f66618e32d618216b669cd2da0be16.jpeg)

Yesterday I also struggled the entire day to put a IF statement inside a “Call from database” statement. It only works without IF. This is why I tried to write a query in the KEY. The proble is that I don’t know how to write… I think it should be something like:

const rootRef = firebase.database([https://myvocab-30705.firebaseio.com/](https://myvocab-30705.firebaseio.com/)).ref();

rootRef.child(‘Box’).orderByChild(‘Box’).equalTo(‘0’);

This info I got based on this video below:

[![](https://img.youtube.com/vi/sKFLI5FOOHs/maxresdefault.jpg "Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4") ](https://www.youtube.com/watch?v=sKFLI5FOOHs)

My app is in [Thunkable](https://x.thunkable.com/copy/016892717234565cc0a1f0e347601bf2)  
If you click the button TRIAL, you will see that it crashes

And by the way, thanks for trying to help me 🙂

---

<div class="post-metadata">

**Author:** ![Cian\_O\_Sullivan](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cian_o_sullivan/32/34494_2.png) [@Cian\_O\_Sullivan](https://community.thunkable.com/u/Cian_O_Sullivan)\
**Post date:** [April 22, 2019, 12:39pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/6 "2019-04-22T12:39:23Z")

</div>

Ok there are clearly some bugs.

You cant send the SQL type query through a key string I dont think. It was not designed or formatted for it.

[https://firebase.google.com/docs/reference/rest/database/](https://firebase.google.com/docs/reference/rest/database/)

You can use Firebase REST API found ⬆

You can use these blocks here ⬇

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/4/64ba90e37dafb5193c7626cec0bfc22945aebd31.png)

---

<div class="post-metadata">

**Author:** ![IWendling](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/iwendling/32/31718_2.png) [@IWendling](https://community.thunkable.com/u/IWendling)\
**Post date:** [April 22, 2019, 2:58pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/7 "2019-04-22T14:58:54Z")

</div>

> [@Cian\_O\_Sullivan](#):
>
> se Firebase REST API fou

Wow, you are being so nice to me. Thank you for taking your time.

I am happy to know the problem is the BUG, and not ME! 🤣🤣🤣🤣  
As I’m a beginner and this is my very first app, I can never tell one problem from another.

Let me learn how to use this API-thing and see if I can use it.

Thank you 😍😘

---

<div class="post-metadata">

**Author:** ![Cian\_O\_Sullivan](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cian_o_sullivan/32/34494_2.png) [@Cian\_O\_Sullivan](https://community.thunkable.com/u/Cian_O_Sullivan)\
**Post date:** [April 22, 2019, 3:02pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/8 "2019-04-22T15:02:23Z")

</div>

The Web function will give lots of flexibility. Its not perfect, and in X there is still lots of room to grow.

Classic gives more certainty, however you dont have the iOS option.

Let me know if there are issues with how to use the API functions.

---

<div class="post-metadata">

**Author:** ![maxb](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/maxb/32/35200_2.png) [@maxb](https://community.thunkable.com/u/maxb)\
**Post date:** [July 3, 2019, 2:50pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/9 "2019-07-03T14:50:25Z")

</div>

@IWendling I feel I can help you, but I’d like to understand what do you want to display exactly

---

<div class="post-metadata">

**Author:** ![maxb](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/maxb/32/35200_2.png) [@maxb](https://community.thunkable.com/u/maxb)\
**Post date:** [July 3, 2019, 3:21pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/10 "2019-07-03T15:21:45Z")

</div>

This should be the solution you need, the last comments should be what you want to do

> [@How to use Firebase in iOS without Get-Taglist-Component?](http://community.thunkable.com/t/how-to-use-firebase-in-ios-without-get-taglist-component/19992/45):
>
> Hello I have almost the same problem but my situation is a bit more complicated … my app interfaces with firebase which is composed as follows: il file json che produce è questo: {“articoli”: { “art1” : { “contenuto” : “contenuto articolo”, “css” : " css", “data” : “04/01/18”, “titolo” : “titolo articolo” }, “art2” : { “contenuto” : “contenuto articolo”, “css” : “”, “data” : “08/01/18”, “titolo” : “titolo articolo” }, “art3” : { “contenuto” : “contenuto articolo”…

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:12pm UTC](https://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/11 "2024-11-08T12:12:21Z")

</div>


