Jump to content

[SOLVED] Dynamic RSS


LiamH

Recommended Posts

Hi all.

 

I've been trying to create some code for dynamic RSS, but failing miserably with it. When I go to validate it, there's always problems. But changing them doesn't seem to get me anywhere. I'll be honest, I don't really know what I'm doing and have been trying to follow several tutorials and getting errors in them all.

 

This is the code I'm using;

 

<?php
header('Content-Type: text/xml');

echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>Gamedot.</title>
<description>The latest news, reviews and features for all consoles, the PC and handhelds.</description>
<link>http://www.gamedot.co.uk</link>';

$get_articles = "SELECT ArticleID, Headline, ArticlePreview, 
DATE_FORMAT(Date,'%a, %e %b %Y %T') as formatted_date 
FROM tblArticles ORDER BY Date DESC LIMIT 2";

$articles = mysql_query($get_articles) or die(mysql_error());

while ($article = mysql_fetch_array($articles)){
      
    echo '
       <item>
          <title>'.$article[Headline].'</title>
          <description><![CDATA[
          '.$article[Preview].'
          ]]></description>
          <link>http://www.gamedot.co.uk/article.php?ArticleID='.$article[ArticleID]</link>
          <pubDate>'.$row[formatted_date].' GMT</pubDate>
      </item>';
}
echo '</channel>
</rss>';
?>

 

Has anyone got any experience in creating a dynamic RSS that could help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/
Share on other sites

What errors are you getting? Also try this (some of your quotes were off):

<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>Gamedot.</title>
<description>The latest news, reviews and features for all consoles, the PC and handhelds.</description>
<link>http://www.gamedot.co.uk</link>';

$get_articles = "SELECT ArticleID, Headline, ArticlePreview, 
DATE_FORMAT(Date,'%a, %e %b %Y %T') as formatted_date 
FROM tblArticles ORDER BY Date DESC LIMIT 2";

$articles = mysql_query($get_articles) or die(mysql_error());

while ($article = mysql_fetch_array($articles)){
      
    echo '
       <item>
          <title>'.$article['Headline'].'</title>
          <description><![CDATA[
          '.$article['Preview'].'
          ]]></description>
          <link>http://www.gamedot.co.uk/article.php?ArticleID='.$article['ArticleID'].'</link>
          <pubDate>'.$row['formatted_date'].' GMT</pubDate>
      </item>';
}
echo '</channel>
</rss>';
?>

Link to comment
https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870927
Share on other sites

OK, thanks for the help so far. Seem to be getting somewhere now thanks to you guys. I've updated it, the link is now http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.gamedot.co.uk%2Frss.php

 

The main error I'm getting now is pubDate must be an RFC-822 date-time: GMT

 

Not sure what that means  ???

Link to comment
https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870955
Share on other sites

Once you get it to run as a php file then you can use mod rewrite as follows:

RewritRule ^rss.xml rss.php

in your .htaccess file.  That way anybody can write rss.xml and it will open your xml.php file but look like it is opening rss.xml(which won't actually exist).

 

Do get it running as rss.php first though.

Link to comment
https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870962
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.