动态Rss Feed无法填充数据库中的数据

时间:2012-05-07 11:34:53

标签: php mysql rss

动态RSS Feed的以下语法会显示包含频道输出的Feed页面http://www.site.com.com/rssfeed.php,但无法从<item> </item>标记中定义的数据库填充动态数据。

<?php require_once('mysqlconnection.php'); ?>
<?php
mysql_select_db($database_rssfeed, $rssfeed);
$query_rssfeed = "SELECT * FROM rssfeed ORDER BY id DESC";
$rssfeed = mysql_query($query_rssfeed, $rssfeed) or die(mysql_error());
$row_rssfeed = mysql_fetch_assoc($rssfeed);
$totalRows_rssfeed = mysql_num_rows($rssfeed);

$rss = '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[Test || Rss Feed]]></title>
<link>http://www.site.com.com/rssfeed.php</link>
<description><![CDATA[Rss Feed]]></description>
<lastBuildDate>'.date('D, d M Y h:i:s O').'</lastBuildDate>
<docs>http://www.test.com</docs>
<language>en</language>
';


//Call data within <item> </item>

while ($row_rssfeed = mysql_fetch_assoc($rssfeed));  {
$rss .= '<item>
<title><![CDATA['.$row_rssfeed['title'].']]></title>
<description><![CDATA['.$row_rssfeed['description'].']]></description>
<link><![CDATA['.$row_rssfeed['link'].']]></link>
<pubDate><![CDATA['.$row_rssfeed['date'].']]></pubDate>
<guid><![CDATA['.$row_rssfeed['link'].']]></guid>
</item>';
}
//<![CDATA[]]>  not to break the XML structure of my feed
$rss .= '</channel></rss>';
header ("content-type: text/xml");
echo $rss; //Output the feed to web browser

mysql_free_result($rssfeed);
?>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

从此行中删除分号

while ($row_rssfeed = mysql_fetch_assoc($rssfeed));  {