I'm having a kind of timeline such as in twitter/facebook, I have a main view, and I need to get the latest updates (timer), and be able to get previous updates (scrolling down). I limit the main view to 25 updates.
I have these columns (more but not relevant)
col_id - auto increment
col_date - timestamp
col_content the content
Basically with queries like these:
SELECT *
FROM table
WHERE col_id < $col_id
ORDER BY com_id DESC
LIMIT 0, 25
Currently, I'm sorting by col_id, and this way I can send the highest col_id used to get the latest updates (e.g. WHERE col_id > $col_id
), and I have the smallest col_id to get previous updates (WHERE col_id < $col_id
)
But I need everything to be sorted by date. But then I can't use the col_id to gather new/previous updates. So I could use the date, however if there are multiple columns with the exact same timestamp, and the 25 limit cuts it somewhere in the middle, I can't use WHERE col_date > $col_date
, because I would miss updates.
I could use WHERE col_date >= $col_date
, but then I need to ignore the dupes from the new ones with the current ones. I can also imagine a situation where there are over 25 updates with the same timestamp, and then I would be getting nowhere.
Is there some way I can combine the date and col_id? Or maybe a new column? I don't know how to tackle this issue.
Thanks!