Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve only new data?

Tags:

I'm trying to create simple notification system for my site admin, and I need to send only real-time messages to every admin user. But when I use firebase it loads old data on every page, and user see all messages from database. If I set limit(1) user will see last notification on every page reloading:

var eventsList = new Firebase('https://*****-messages.firebaseio.com/');  eventsList.on('child_added', function(message) {     var message = message.val();     $.notification(message.message); }); 

How I can load only new messages, without old notification history?

like image 615
inlanger Avatar asked Aug 16 '13 10:08

inlanger


People also ask

How do I get new data in SQL?

Here is the syntax that we can use to get the latest date records in SQL Server. Select column_name, .. From table_name Order By date_column Desc; Now, let's use the given syntax to select the last 10 records from our sample table.

How do I select only data in SQL?

select first, last from empinfo where last LIKE '%s'; This statement will match any last names that end in a 's'. select * from empinfo where first = 'Eric'; This will only select rows where the first name equals 'Eric' exactly.

What is entry in DB?

The process of entering data into a computerized database or spreadsheet. Data entry can be performed by an individual typing at a keyboard or by a machine entering data electronically.


1 Answers

This is by design, in a real-time system there is no concept of the "latest" data because it's always changing. However, if you want to only display items added to the list after the page has loaded, you can do the following:

var newItems = false; var eventsList = new Firebase('https://*****-messages.firebaseio.com/');  eventsList.on('child_added', function(message) {   if (!newItems) return;   var message = message.val();   $.notification(message.message); }); eventsList.once('value', function(messages) {   newItems = true; }); 
like image 139
Anant Avatar answered Oct 14 '22 18:10

Anant