Answer the question
In order to leave comments, you need to log in
How to load news not in chronological order?
The site has a news feed, while the user is scrolling through the first 10 news, a few more new ones can be added to the database or some of those that the user is watching right now can be deleted
. There is also a view mode by rating, where the rating can be from 0 to 5, of course, with In this scenario, the output chronology deteriorates, and it is no longer possible to rely on the latest news ID when loading new ones (WHERE `id` > blah_blah) The
request looks something like this:
SELECT *, (хитрая формула расчета рейтинга) as rating FROM `news`
WHERE (некое условие для дополнительной сортировки по категориям)
ORDER BY `rating` ASC
LIMIT 20
Answer the question
In order to leave comments, you need to log in
Just use pagination:
SELECT *, something FROM `news`
WHERE (некое условие для фильтрации по категориям) AND date < "time of page hit"
ORDER BY `something` ASC
LIMIT 20, 20
(page_num-1)*page_size
. The second number is, as usual, the number of posts per page. decide for yourself what is more important, what is less important and indicate this with a comma in order by
ps where - this is not sorting, but selection
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question