You are not logged in.
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
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.
Last edited by caelestis (2010-01-06 07:37:55)
Offline
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
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