Jump to content

Recommended Posts

Example is: https://twitter.com/statuses/user_timeline/kevinhart4real.xml

 

I have all the relevant information I need that i'd like to go in the field, I just need to know how to dynamically create the file with the content and have it update at specific intervals.

 

Any one have any ideas (with PHP)

 

So far I have come up with this:

 

$link = mysql_connect('localhost','root','');
mysql_select_db('test',$link);  

$result = mysql_query('SELECT `nationid`,`ruler`,`nation`, `resource1`, `resource2`, `alliance` FROM `nation`');  

$doc = new DomDocument('1.0');  

$root = $doc->createElement('nationlist');
$root = $doc->appendChild($root);  

while($row = mysql_fetch_assoc($result))
{
    $nation= $doc->createElement('nation');
    $nation = $root->appendChild($nation);


foreach($row as $fieldname => $fieldvalue)
{
    $child = $doc->createElement($fieldname);
    $child = $car->appendChild($child);
    //add data to the new element
    $value = $doc->createTextNode($fieldvalue);
    $value = $child->appendChild($value);
    
}  
}
$doc->save("nations.xml");

Now that generates 1 .xml file with all the details returned from my query. (also don't bash me for using mysql, it's a quick test)

 

What I would like to do is create a new file for each record in my table and have only the values in that recorded saved to its respective file.

Link to comment
https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/
Share on other sites

Why do you need to create any actual files? PHP can generate the xml when a request is made, just as it is generally used to generate html when a request is made.

Hi there thorpe.

 

I need to generate actual files, because the content within them need to be specific to the actual user account.

 

Would you recommend another solution for my situation?

You don't need to generate files, as Thorpe said php is dynamic, so it can generate the file content on the fly.

with a bit of htaccess help to map xml urls to a php script (http://mysite.com/user.xml), or path_info (http://mysite.com/timeline.php/user.xml)(both using apache, other webservers you will have to lookup how to create a virtual file mapping) or just use url parameters (http://mysite.com/timeline.php?u=user).

 

To generate actual files at specific intervals, you will probably looking at cron with a long running php process, or someway to update users while browsing your site.

 

Of all Thorpe's suggestion is by far the easiest method.

 

 

You don't need to generate files, as Thorpe said php is dynamic, so it can generate the file content on the fly.

with a bit of htaccess help to map xml urls to a php script (http://mysite.com/user.xml), or path_info (http://mysite.com/timeline.php/user.xml)(both using apache, other webservers you will have to lookup how to create a virtual file mapping) or just use url parameters (http://mysite.com/timeline.php?u=user).

 

To generate actual files at specific intervals, you will probably looking at cron with a long running php process, or someway to update users while browsing your site.

 

Of all Thorpe's suggestion is by far the easiest method.

 

Thanks that solution would make more sense now that I think of it.

 

Now if I want to use url parameters, all i'd have to do is use the $GET array right? (Ensuring everything is sanitized of course)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.