views:

47

answers:

3

Hi all,

I have a simple php code which prints data from a SQLite database. Basically $query ="Select A from B". This all works fine. & when the sqlite db updates, i can refresh the page & the new data displays.

Want i am aiming to achieve is to refresh this data automatically every 5-10 seconds without having to reload the entire page. I am also trying to avoid using iframes as there is about 20 of these on the page all displaying different data.

This has been driving me mad the last few days, Does anyone know of a way to do so? My thought have been javascript, jquery or AJAX?

Other than that can you get sqlite data with javascript alone, without php? & then implement something like the below on the element only? without the page reloading??

setTimeout("location.reload();",5000);

Thank you in advance.

+1  A: 

Ajax is what you need.

Two options that I use quite a bit, both with plusses and minuses:

  1. Jquery, easy to learn, quick to deploy, and very configurable
  2. XAJAX -- AJAX for PHP. It's not the best thing out there, but if you're scared of Javascript, this allows you to do AJAX from PHP Functions, which can be easier for PHP guys to understand.

In essence, output your code to a specific DIV, then use AJAX to update that div with data it queries from the DB.

bpeterson76
+4  A: 

You can do it using setInterval(), passing a jQuery ajax command and the time.

Or take a look at this jQuery plugin http://plugins.jquery.com/project/ekko

André Gadonski
+2  A: 

I'd recommend using jQuery as it's easy to do this sort of thing with the built in ajax function. Download jQuery and embed in your page or embed via a CDN.

1.) create a PHP file that outputs the content you want to "update" every few minutes. No headers/footers, etc.

2.) Put the content you want to refresh in a div with some specific id.

3.) Check out the simple example for using setInterval and ajax/load on this page.

vsz
Thanks for your suggestions,
are you embedding the ajax.js multiple times via the includes php files by chance?
vsz