yuli chika
yuli chika

Reputation: 9221

Why does this XML not render in the browser the way I want?

I want to use php to create RSS from mysql. I can see the content in the page source code. But I can not see the item part in Web Browser(IE, Firefox or Opera). the Web Browser just show

`Your RSS Feed Name or Website Name

A description of your feed or site.`

<?PHP
require_once ('mysql_connect.php'); 
    //SET XML HEADER
    header('Content-type: text/xml');

    //CONSTRUCT RSS FEED HEADERS
    $output = '<rss version="2.0">';
    $output .= '<channel>';
    $output .= '<title>Your RSS Feed Name or Website Name</title>';
    $output .= '<description>A description of your feed or site.</description>';
    $output .= '<link>http://www.yoursite.com/</link>';
    $output .= '<copyright>Your copyright details</copyright>';

    //BODY OF RSS FEED
    mysql_select_db("rss", $db);
    $result = mysql_query("SELECT * FROM rss limit 15",$db);
        while ($row = mysql_fetch_array($result)) {
            $output .= '<item>';
                $output .= '<title>'. $row['title'] .'</title>';
                $output .= '<description>'. $row['content'] .'</description>';
                $output .= '<link>'. $row['link'] .'</link>';
                $output .= '<pubDate></pubDate>';
            $output .= '</item> ';
        }
    mysql_close($db); 
    //CLOSE RSS FEED
    $output .= '</channel>';
    $output .= '</rss>';

    //SEND COMPLETE RSS FEED TO BROWSER
    echo($output);

?>

the xml source looks like:

<rss version="2.0">
<channel>
<title>Your RSS Feed Name or Website Name</title>
<description>A description of your feed or site.</description>
<link>http://www.yoursite.com/</link>
<copyright>Your copyright details</copyright>
  <item>
    <title>MILAN, ITALY - SEPTEMBER 26: Models walk the runway at Emi&hellip</title>       
    <description>Date: Sep 26, 2009 7:45 PMNumber of Comments on Photo:0View Photo&hellip;</description>
    <link>http://picasaweb.google.com/roxyluvtony/KendraSpears#5551895410815389042</link>
    <pubDate></pubDate>
  </item>
  ...
</channel>
</rss>

Upvotes: 2

Views: 580

Answers (3)

Demian Brecht
Demian Brecht

Reputation: 21368

Maybe due to your content type? Try Content-Type: application/rss+xml rather than Content-type: text/xml

Upvotes: 0

jrn.ak
jrn.ak

Reputation: 36619

Moving my comment to an Answer...

it's not valid XML because of the &hellip; entity in your <title> and <description> nodes.

Wrap those strings with a <![CDATA[tag]]> and try again.

Upvotes: 1

fiiv
fiiv

Reputation: 1287

You are fetching a regular array instead of an associative array. It should be:

while ($row = mysql_fetch_assoc($result))

The difference is mysql_fetch_array() will fetch with integers as indexes ($row[0]), and mysql_fetch_assoc() gives you names ($row['title']).

Upvotes: 0

Related Questions