Forum Moderators: open

Message Too Old, No Replies

How to automatically refresh XML file

every 2 hours

         

petra

9:19 am on Jul 22, 2006 (gmt 0)

10+ Year Member



The php code to produce the XML is located in an XML file.

There is also an htaccess file that tells the server to treat xml files as php.

The XML displays perfectly however the job I'm doing requires that the XML feed automatically refreshes every 2 hours without the user manually refreshing the page.

Is this possible?

Here's the code I'm using in the .xml file:

<?php
//for the output
header("Content-type: text/xml");

//to create connection to database
$connection = mysql_connect('', '', '')
or die ("could not connect to database");

//to select the database here test is the sample database come with mysql
$db = mysql_select_db("",$connection)
or die ("Couldn't select database.");

$rs = mysql_query("select * from ",$connection)
or die ("invalid query");

//count the no. of columns in the table
$fcount = mysql_num_fields($rs);
$xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
//you can choose any name for the starting tag
echo ("<result>");
while($row = mysql_fetch_array( $rs ) )
{
echo ("<tablerow>");
for($i=0; $i< $fcount; $i++)
{
$tag = mysql_field_name( $rs, $i );
echo ("<$tag>". $row[$i]. "</$tag>");
}
echo ("</tablerow>");
}
echo ("</result>");
?>

petra

9:31 pm on Jul 22, 2006 (gmt 0)

10+ Year Member



Anyone?

coopster

12:50 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So the page is sitting active in the user's browser and you want the user's browser to initiate a refresh? I believe the only way to accomplish this task is with a meta refresh.

petra

3:44 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Hi Coopster,
Yes I tried the meta refresh however the file is an xml file so its not executing the refresh. Is there a special way to refer to the refresh within the code in the original post so that it works?

coopster

8:12 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Right. XML was created to structure, store and to send information, not display it. Have a look at something like an XML data island and see if that is going to work for you.

petra

8:20 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Thanks but I'm not looking to display the XML file, only to refresh it so that everytime the database is updated it s reflected in the XML feed without a user having to refresh the page.

coopster

8:27 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm a little confused now. Is the file being created from data in your database and then you want to store the xml file on the server? If so, you shouln't be sending out any headers, you should be writing the data out to your local filesystem for the user to pick up on their next visit to your data.

petra

9:18 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Exactly, the file is an xml file that has php code in it (see above)to create an XML feed out of data in the database. Currently it does update to reflect changes in the DB every time a user visits the page however I was just curious about wether or not I will be able to add anything in the code to make the page refresh on its own (without the user having to manually refresh the page).

coopster

9:26 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The page is being built dynamically, it will always be the latest data from the database the way you have it coded. I must be missing something in our communication here.

petra

9:32 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Yes it is dynamic but I was wondering if I could add a meta refresh to that code so that it automatically refreshes every, lets say 2 hours without the user actually having to manually refresh the page.

coopster

11:21 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



In his browser?

petra

11:39 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Yup, is that possible?

coopster

10:59 am on Jul 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If it is in his browser then you are indeed displaying the data -- I feel like we have come full circle ;)

Can you explain in very plain words exactly what occurs in each step of the process? Not your code, I understand the code, it's the general step-by-step process I am trying to get my head around here.

petra

5:57 pm on Jul 28, 2006 (gmt 0)

10+ Year Member



Sorry Coopster, was on holiday in an internet-less part of the UK (didn't think that was still possible!)

In a nutshell the code in the original post is in a file named xml.xml I just want that page (mysite.com/xml.xml) to automatically refresh in the same way as the active posts list page does on webmasterworld (ie on its own without the user refreshing the page through the browser.)

Hope this makes it clearer, if it doesn't don't worry about it mate and thanks for your help.

coopster

3:37 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No worries. I think that what you are describing can be accomplished using an "XML data island" -- google that phrase and you'll see some examples.

petra

9:06 am on Jul 30, 2006 (gmt 0)

10+ Year Member



Thanks Coopster :-)