开发者

How would I go about selecting one entry at a time while prioritizing on newest ones?

How would I 开发者_JS百科go about selecting one entry at a time while prioritizing on newest ones? So, in the end, the newly added entries are seen before the old one. The problem is new entries are added from time to time, and I want them to be shown first and I do not want to show already seen entries.


OK, so let's attack this issue two ways:

To show newly added entries first, you'd do something like:

SELECT * FROM customers ORDER BY customer_id DESC;

And if you want to leave out items that have already been viewed, you'll have to flag them in the DB somehow. Maybe add a did_view integer column with a default value of 0 and set it to 1 every time the newest results are pulled:

UPDATE customers SET did_view = 1;

Then, on the next page load, you'll pull the new entries:

SELECT * FROM customers WHERE did_view = 0 ORDER BY customer_id DESC;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜