1

当您拉取 RSS 提要时,它会显示 1 个帖子,但在该帖子中,所有其他帖子都会显示。我检查了我所有的关闭,并一遍又一遍地修改了代码,但看不出问题出在哪里。在某些 RSS 阅读器上,它只是说错误无法读取提要。但在其他人我有这个问题。

任何方向都会有所帮助。下面的代码:


<?PHP

$host = "****";
$un = "****";
$pw = "****";
$db = "****";

$link = mysql_connect($host, $un, $pw) or die(mysql_error());
if(!$link){ die("Could not connect to MARTHA GRAEFF - AROUND IN STYLE database: " . mysql_error()); }
$selectDB = mysql_select_db($db, $link) or die(mysql_error());
if (!$selectDB){ die ("Can't use MARTHA GRAEFF - AROUND IN STYLE database: " . mysql_error()); }

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

echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
echo '<rss version="2.0">';
echo '<channel>';
echo '<title>TITLE OF THE FEED</title>';
echo '<description>BLOG DESCRIPTION</description>';
echo '<link>http://www.example.com</link>';

$get_articles = "SELECT `id`, `title`, `image`, `text`, DATE_FORMAT(`date`,'%a, %e %b %Y') as `date` FROM `posts` WHERE `date` <= CURDATE() ORDER BY `added` DESC LIMIT 20";
$articles = mysql_query($get_articles);

while($a = mysql_fetch_array($articles)){
echo "<item>";
    echo "<title>" . $a['title'] . "</title>";
    echo "<description><![CDATA[";
        echo "<img src='http://www.example.com/images/db/thumb.php?src=" .     $a['image'] . "&w=650' width='650' alt='" . $a['title'] . "' /><br />";

        $pid = $a['id'];
        $q = "SELECT * FROM `photos` WHERE `post_id`='" . $pid . "' ORDER BY `added` ASC";
        $r = mysql_query($q);     
        while($i = mysql_fetch_array($r)){
            echo "<img src='http://www.example.com/images/db/thumb.php?src=" . $i['image'] . "&w=650' width='650' alt='" . $a['title'] . "' /><br />";
        }

        echo $a['text'];
    echo "]]></description>";
    echo "<link>http://www.example.com/post.php?id=" . $a['id'] . "</link>";
    echo "<pubDate>" . $a['date'] . " EST</pubDate>";
echo "</item>";
}
echo "</channel>";
echo "</rss>";  

?>
4

1 回答 1

0

您可以 在 sql 查询和 foreach 时使用带有mysql_fetch_object()的对象

$get_articles = "SELECT `id`, `title`, `image`, `text`, DATE_FORMAT(`date`,'%a, %e %b %Y') as `date` FROM `posts` WHERE `date` <= CURDATE() ORDER BY `added` DESC LIMIT 20";
$articles = mysql_query($get_articles);

while ($obj = mysql_fetch_object($articles)) {
        $array[$obj->id]['id'] = $obj->id;
        $array[$obj->id]['title'] = $obj->title;
        $array[$obj->id]['image'] = $obj->image;
        $array[$obj->id]['date'] = $obj->date;  
}

和输出:

foreach ($array as $k) {
echo "<item>";
   echo "<title>" . $k['title'] . "</title>";
   echo "<description>" . $k['image'] . "</description>";
   echo "<date>" . $k['description'] . "</date>"; 
echo "</item>";
} 

这是一个例子,您必须按照自己的方式编写代码

于 2012-08-15T20:08:25.250 回答