J
J
Junior2018-09-15 08:36:35
PHP
Junior, 2018-09-15 08:36:35

How to display only new records from the database?

When you open the site, the 10 newest news are displayed. Below there is a button to download older news. The question is, there is a JS interval on the page that sends an AJAX request every 5 seconds.
How can I make it show only unloaded news?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
PloAl, 2018-09-15
@PloAl

News can also have a date field.
On the client, you get the largest date, send it to the server, and on the server, in the request, make the condition to select records only with a larger date.

A
Alexey, 2018-09-15
@Softovick

It all depends on which database you are using.
Some databases have a so-called subscription to data changes or a filter for updated data.
I also see a small logical inconsistency - it displays 10 latest news for you, why overload the application logic with filtering for loaded or unloaded news, if it still displays 10 latest ones?
Well, I just do not understand your idea, apparently, there was a block with 10 news. We made a request, there are no new ones - is the block empty now? Or if there are 3 new ones, will the block consist only of these 3? Or all also 10 last? If everything is also the last 10, what's the point of complicating the query to the server and the database if it still returns the last 10?

A
Andrey Mokhov, 2015-04-03
@mokhovcom

too lazy to even look at the doc
SELECT '{"id":184}'::json->'id'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question