I am trying to retrieve data from the Firebase, data retrieve has done but there has a problem, I can’t display data descending order for firebase database. In firebase, I can use orderByChild() to get data but I already use it and there have no option to use orderByChild() twice.
I have applied some jQuery code to retrieve data, here I want to reverse my array data.
I have followed these code:
<script type="text/javascript"> var getUser = firebase.database().ref('notification/').orderByChild('fk_user_id').equalTo('<?php echo $this->session->userdata("user_id"); ?>'); getUser.on('value', function(snapshot) { var data=snapshot.val(); Object.keys(data).forEach(function(k) { $('#notifiID').append('<tr><td>'+data[k]['message']+'</td><td>'+data[k]['created_date']+'</td></tr>'); }); }); </script>
If you want to reverse object array while you fetch data from the database just put the reverse() function.
Follow this example code:
<script type="text/javascript"> var getUser = firebase.database().ref('notification/').orderByChild('fk_user_id').equalTo('<?php echo $this->session->userdata("user_id"); ?>'); getUser.on('value', function(snapshot) { var data=snapshot.val(); Object.keys(data).reverse().forEach(function(k) { $('#notifiID').append('<tr><td>'+data[k]['message']+'</td><td>'+data[k]['created_date']+'</td></tr>'); }); }); </script>
Question and answer is powered by AnsPress.io