...

View Full Version : RSS Feed valid but not working



ro1960
08-15-2008, 04:04 PM
Hi I just tried my firt PHP RSS feed. I built the code like I would an HTML file from a PHP script.

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/XXXX.php";
if (file_exists($filename)) include("inc/XXXX.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&amp;id=".$id."&amp;section=news</link>\n";
echo "</item>\n";
}
?>


</channel>
</rss>

hinch
08-15-2008, 04:13 PM
cursory glance code looks good xml looks formatted correctly have you tried looking at the feed in something other than a web browser ? if it appears blank in a web browser have you tried viewing source see if its there just the web browser being special and not displaying it?

Have you tried adding in some debugs ie: echo "1"; echo "2"; etc after every execution line so you can see if its actually doing anything at all or just failing and not reporting an error.

also look at http://www.codingforums.com/external.php and compare against your's for formatting just to be sure

ro1960
08-15-2008, 05:18 PM
After looking at this link, I wondered if the issue could be the file extension. I am using .xml and the codingforums link uses .php.
I tried but it didn't make a difference.

I added some echo as well and nothing showed up.

I am wondering if PHP is simply not being parsed. Could it be a server setting?

ro1960
08-15-2008, 05:26 PM
I also tried a stand-alone news reader and nothing showed up.

hinch
08-15-2008, 05:28 PM
for it to process your php code the file would have to be called .php for starters something like rss.php is fine

I've just cut the DB stuff out of your code and ran it against my local server



<?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
$h_news_title = "title";
$id="ID";
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&amp;id=".$id."&amp;section=news</link>\n";
echo "</item>\n";
?>
</channel>
</rss>


Output



<?xml version="1.0"?>
<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>
<item>
<title>title</title>
<description>title</description>
<link>http://www.MYSITE.com/pl.php?p=news_item.php&amp;id=ID&amp;section=news</link>

</item>
</channel>
</rss>


Change your &amp; to just & its xml not html.

asside from that I suspect the problem is with your select and while ()

ro1960
08-15-2008, 06:16 PM
Hi all, I feel like a fool! I forgot my db connection script so there was no db connection. Now after a few adjustments, it is working.

Thank you for you help!

oesxyl
08-15-2008, 06:23 PM
Change your &amp; to just & its xml not html.
exactly for this reason must be &amp; and not &.

regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum