/    Sign up×
Community /Pin to ProfileBookmark

MySQL data to XML file

Greetings!!!

How can I write Mysql data in a XML file using PHP for RSS??
Do you have examples??

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@grumpyoldtechsFeb 28.2007 — in the words of blue peter heres one i made earlier:
[code=php]
<? require_once "connection.php";
header("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'." n";
/* echo '<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="rss.xsl"?>'." n"; */
?>
<rss version="2.0">

<channel>
<title>feed title</title>
<link>http://www.url.com/blog/</link>
<description>url.com website title</description>
<?
$query = "SELECT * FROM table ORDER BY id DESC LIMIT 15";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
stripslashes($row['title']);
$year = substr($row['date'], 0, 4);
$month = substr($row['date'], 5, 2);
echo "<item> n";
echo "<title>".$row['title']."</title> n";
echo "<link>http://www.url.com/blog/".$year."/".$month."/</link> n";
echo "<description>Blog Entry: ".$row['date']."</description> n";
echo "</item> n";
echo "n";
}
?>
</channel>
</rss>
[/code]


you will need to edit it to work for you tho (bit of the sql query, and the link/field names)

i also used url_rewrite on the file to allow rss.php to be asscessed by rss.xml

.NET mag also had an online article from one of their previous issues:

http://www.netmag.co.uk/zine/php/syndicate-with-xml
Copy linkTweet thisAlerts:
@theuedimasterFeb 28.2007 — Is connection.php the file connecting to the mysql database?
Copy linkTweet thisAlerts:
@grumpyoldtechsFeb 28.2007 — yup.

i never have my connection script within the user accessed file
Copy linkTweet thisAlerts:
@Paulo_MonteiroauthorMar 01.2007 — i also used url_rewrite on the file to allow rss.php to be asscessed by rss.xml[/QUOTE]

What do you mean? That code must be in a php file ... how can i put the information in a xml file for the RSS readers automatically??
Copy linkTweet thisAlerts:
@grumpyoldtechsMar 01.2007 — it is an xml file.

the file extension means nothing if you look at the script i change the mimi type to text/xml.

For php to execute the script the extension does however need to be .php (depending on your servers configuration)

so if your running on an apache server you can have this in a .htaccess file in your website root:
<i>
</i>Options +FollowSymLinks
RewriteEngine on
RewriteRule rss.xml$ rss.php


for rss feeds to work you don't have to have a .xml file extension just a xml mimi type.
×

Success!

Help @Paulo_Monteiro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...