views:

122

answers:

3

Hello,

I need to update my UI (webpage) periodically with new values. I have PHP code that grabs the values form a database, but I am not 100% sure on what is the best way of getting that data to the UI side.

The complication here is that: 1. I need to constantly update the values (every second) 2. I need to update many different areas of the page independently

Thanks,

+5  A: 

You use javascript to ask a PHP script for the values. You don't push from PHP to javascript.

You'll probably want to use AJAX and setInterval()

http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

Scott Saunders
+3  A: 

What you probably want is comet, not setInterval as you'll overwhelm your servers with a lot of unnecessary traffic.

This is what Facebook does for their chat features, and their live feeds (or at least used to do, I haven't looked at it in quite some time.

altCognito
Yes. For now you'll have to look in to doing comet. If your planning on getting a product out soon I wouldn't bother with WebSockets just yet, only Webkit supports them so far! :)
Ronald
+2  A: 

You should also look into http://dev.w3.org/html5/websockets/ More and more browsers starts to support them and it's a good way to constantly pass information back and forth.

You can check for browser support and use it if it exist.

Milar