Page 1 of 1

Rss script..

Posted: Mon Apr 13, 2009 12:38 am
by radhoo
Hallo,

I have some problems with a script that should generate a rss feed for a web page. The validator prompts me some errors right here.

Also the code doesn't return any data from sql. Can you help me with this?
Here is the code:

Code: Select all

 
<?php
header("Content-type: application/rss+xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
 
// Set RSS version.
echo "<rss version=\"2.0\">";
 
include("config.php");
 
// Start the XML.
echo "
<channel>
<title>Press Release</title>
<description>A description of the feed contents</description>
<link>http://www.quanticlab.com/</link>";
 
$sql="SELECT * FROM news LIMIT 10";
$result = mysql_query($sql);
 
while($row=mysql_fetch_array($result)){
echo"
<item>
<link>http://www.quanticlab.com/press_release.php?id_news=".$row[id_news]."</link>
<guid isPermaLink=\"true\">http://www.quanticlab.com/press_release.php?id_news=".$row[id_news]."</guid>
<title>".$row[news_titlu]."</title>
<description><![CDATA[".$row[news_short]."]]></description>
</item>"
 
}
 
echo "
</channel>
</rss>";
 
 
?>
 


Thanks

Re: Rss script..

Posted: Mon Apr 13, 2009 12:50 am
by requinix
http://www.quanticlab.com/feed.php
I don't see anything. At all.

Re: Rss script..

Posted: Mon Apr 13, 2009 12:53 am
by radhoo
Yes, this is the problem... it doesn't return anything. Maybe you can try the code on your data base if you can...

The thing is that if I remove the whole while cycle, the page displays like a rss page (without data of course) maybe inside the while there is a problem...

Re: Rss script..

Posted: Mon Apr 13, 2009 1:14 am
by requinix
Hmm... ah, there it is.

Most of the time when you get a blank page it means there's a syntax error. You'd see an error message if PHP was configured to show them. Which is why it's always a good idea to turn up error_reporting and to enable the display_errors INI settings on production servers. Which is where you should be developing.

As for the error: the echo statement in the loop is missing the semicolon.

Re: Rss script..

Posted: Mon Apr 13, 2009 1:31 am
by radhoo
Yep, I've put a semi colon there and also some quotation marks inside the $row[].

But there is still a problem... when I enter the page it tries to download it... :?

-------------
Solved. The problem was caused by the UTF encoding. I removed that line and it works now.