Forum Moderators: coopster
The DB query works, I tested it in phpMyAdmin, the feed validates at feedvalidator.org but the page remains empty.
I wonder what's wrong with my code:
<?xml version="1.0"?>
<?php header("Content-type: text/xml"); ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>
<atom:link href="http://www.MYSITE.com/result_news.xml" rel="self" type="application/rss+xml" />
<title>MYSITE.com ¦¦ News</title>
<description>News from my community</description>
<link>http://www.MYSITE.com/news</link>
<?php
$filename = "inc/#*$!X.php";
if (file_exists($filename)) include("inc/#*$!X.php");
$query_news = "
SELECT id, news_title, party_group ,city, state, country
FROM news
WHERE date_start <= CURDATE() AND date_end >= CURDATE()
AND live = '1'
ORDER BY date_created DESC
LIMIT 0,15
";
$result_news = mysql_query($query_news)
or die ("Couldn't execute the News query.");
while ($row_news = mysql_fetch_array($result_news))
{
extract($row_news);
$h_news_title = html_entity_decode($news_title, ENT_QUOTES, "UTF-8");
$h_party_group = html_entity_decode($party_group, ENT_QUOTES, "UTF-8");
$h_city = html_entity_decode($city, ENT_QUOTES, "UTF-8");
$h_country = html_entity_decode($country, ENT_QUOTES, "UTF-8");
echo "<item>\n";
echo "<title>".$h_news_title."</title>\n";
echo "<description>".$h_news_title."</description>\n";
echo "<link>http://www.MYSITE.com/pl.php?p=news_item.php&id=".$id."&section=news</link>\n";
echo "</item>\n";
}
?>
</channel>
</rss>
The major thing I see missing is the header. Place this at the top of the document before anything is echoed. It will tell the browsers the file is an RSS feed.
header('Content-type: application/rss+xml; charset=UTF-8');
instead of
<?xml version="1.0"?>
<?php header("Content-type: text/xml"); ?>
you should have
<?php header("Content-type: text/xml"); ?>
<?xml version="1.0"?>
sending headers after data has already been sent to the browser should throw an error or warning.