views:

22

answers:

1

I have a Section in my website called Recent Updates. in that I will show the latest 5 updates at first when the page is rendered.

When a New update is done at real time, the new update will be appended to the top of the updates list and the last one will be deleted.

My approach:

For this problem, what im doing is, First i renders the page with last 5 recent updates. I am fetching updates from database. When a update is made in realtime, it will be stored in database with flag = 0.

To find out whether any update is made, I have a javascript which calls the ajax page every 4 seconds. The ajax page checks in the db whether any records with flag=0 is present. If any of its there, then it will return back the update with flag=0 and set that flag to 1.

Problem:

It is working fine on a single system. But I havent tested on multiple system at same time. I fears, the each update can be viewed only by single user and its flag is set to 1. So the other users may not get it.

Is there any alternate approach in solving this issue?. May be changing the query or something may yield goodness. Expecing help from experts here.. Any help will be appreciated.

+1  A: 
  1. Each update is stored with a timestamp of when it was created.
  2. Javascript figures out the timestamp of the latest update displayed on the site.
  3. AJAX request asks for "updates newer than [timestamp determined in 2.]" and injects results into page.
  4. Goto 2.
deceze