You are not logged in.

#1 2010-01-06 07:29:43

chsims1
Member
From: Holderness, UK
Registered: 2008-11-25
Posts: 83

Dynamically updating data in a webpage ..... help/suggestions please?

Hi All,

I have a simple delimited text file of current weather observations (less than 20 items) updated every 15 minutes, which I display via an embedded  Flash animation.  I would like to do away with the Flash approach, and display the data in tabular fashion within a webpage.

What do people  consider the best approach to getting the latest data out of the text file and into the webpage?  I already use some simple php to get the data into variables for the Flash approach (simply explode the text file into an array), but I don't know enough php to see how to flexibly use this within html ie use the array variables at later points in the html.

I'm sure that there are several possible approaches here but I lack the depth of knowledge to decide where to start. So, suggestions please, and then I can go do some reading.

Cheers in advance,

Ian

Offline

#2 2010-01-06 07:34:05

caelestis
Member
Registered: 2009-04-04
Posts: 88

Re: Dynamically updating data in a webpage ..... help/suggestions please?

php is run only once and is done so before the user sees the page so it cannot display anything for you. The only way to do this without flash or java is with javascript and asynchronous xml. You may have heard this as AJAX and is what google uses for its suggestions, maps, w/e. I recommend using a javascript toolkit such as Mootools because it is simple, fast, and has better approaches than other frameworks. Simply give an id to a div you want to update regularly, and execute

$('divid').load('pageurl');

and it will inject the contents of the url into the div.

It can call on a php script and every time you load the php file, the php file will get re-executed.

http://mootools.net/

Last edited by caelestis (2010-01-06 07:37:55)

Offline

#3 2010-01-06 09:02:17

chsims1
Member
From: Holderness, UK
Registered: 2008-11-25
Posts: 83

Re: Dynamically updating data in a webpage ..... help/suggestions please?

Thanks for the reply.  I think that it does not matter too much that php only runs once, since people are unlikely to stay on the page for 15 minutes to see the next update. So as long as the page has the latest data on being downloaded, then this should be fine.

Offline

#4 2010-01-06 18:22:54

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: Dynamically updating data in a webpage ..... help/suggestions please?

What you want is probably something like this:

<?php
$vars = explode(/* The file */);

echo '<table>';
foreach ($vars as $row) {
  echo '<tr>';
  foreach ($row as $cell) {
    echo '<td>', $cell, '</td>';
  }
  echo '</tr>';
}
echo </table>';
?>

This is just a guess, as I don't know how your data is actually formatted.

Offline

Board footer

Powered by FluxBB