我尝试制作一个从我的SQL数据库加载数据的RSS源。
当我运行它时,要么将我带到我的互联网浏览器上的RSS阅读器并说“ no content ”,否则它将返回错误:
此页面包含以下错误:第1行第2行的错误:文档末尾的额外内容下面是第一个错误之前的页面呈现。
我使用Dreamweaver制作RSS并在PHP文件上创建它。
<?php require_once('Connections/mydatabase.php'); ?>
<?php
header('Content-type: text/xml');
$mydatabase = mysqli_connect("http://127.0.0.1","root","au291826","db_cms");
$rss = '<?xml version="1.0" encoding="utf-8"?>';
$rss .= '<rss version="2.0">';
$rss .= '<channel>';
$rss .= '<title>My RSS</title>';
$rss .= '<link>http://localhost/cws_files/</link>';
$rss .= '<description>implementation of RSS with PHP </description>';
$rss .= '<language>ar-sa</language>';
$rss .= '<copyright> RSS </copyright>';
mysql_select_db($database_mydatabase, $mydatabase);
$query_getRecent = "
SELECT news.post_id, news.title
FROM news
ORDER BY news.updated
DESC LIMIT 10
";
$getRecent = mysql_query($query_getRecent, $mydatabase) or die(mysql_error());
$totalRows_getRecent = mysql_num_rows($getRecent);
while ($row_getRecent = mysql_fetch_assoc($getRecent)){
$rss .= '<item>';
$rss .= '<link>
http://localhost/cws_files/index.php?post_id=' . $row_getRecent['post_id'] . '
</link>';
$rss .= '<title>' . $row_getRecent['news.title'] . '</title>';
$rss .= '</item>';
}
$rss .= '</channel>';
$rss .= '</rss>';
echo $rss;
?>
答案 0 :(得分:0)
看看这一行:
$rss .= '<title>' . $row_getRecent['news.title'] . '</title>';
结果数组索引不能包含表名,只能包含列名。替换为
$rss .= '<title>' . $row_getRecent['title'] . '</title>';
看看你得到了什么。
这条线看起来也很可疑。
$rss .= '<link>
http://localhost/cws_files/index.php?post_id=' . $row_getRecent['post_id'] . '
</link>';
检查这是否是单行。否则,如果有换行符,请将其更正为一行。
答案 1 :(得分:0)
<?php require_once('Connections/mydatabase.php'); ?>
<?php
//header ("Content-Type:text/xml");
?>
<?php
header('Content-type: text/xml');
$mydatabase = mysqli_connect("http://127.0.0.1","root","au291826","db_cms");
$rss = '<?xml version="1.0" encoding="utf-8"?>';
$rss .= '<rss version="2.0">';
$rss .= '<channel>';
$rss .= '<title>My RSS</title>';
$rss .= '<link>http://localhost/cws_files/</link>';
$rss .= '<description>implementation of RSS with PHP </description>';
$rss .= '<language>ar-sa</language>';
$rss .= '<copyright> RSS </copyright>';
mysqli_select_db($database_mydatabase, $mydatabase);
$query_getRecent = "SELECT news.post_id, news.title FROM news ORDER BY news.updated DESC LIMIT 10";
$getRecent = mysqli_query($query_getRecent, $mydatabase) or die(mysqli_error());
$totalRows_getRecent = mysqli_num_rows($getRecent);
while ($row_getRecent = mysqli_fetch_assoc($getRecent)){
$rss .= print_r($row_getRecent);
$rss .= '<item>';
$rss .= '<link> http://localhost/cws_files/index.php?post_id=' . $row_getRecent['post_id'].'</link>';
$rss .= '<title>' . $row_getRecent['title'] . '</title>';
$rss .= '</item>';
}
$rss .= '</channel>';
$rss .= '</rss>';
echo $rss;
?>