Error while creating xml rss feed from MySQL table



I get the following error when I'm making an XML RSS Feed from a MySQL database on localhost:


Extra content at the end of the document


Here's my code:



<?php
// PDO connect *********
function connect() {
return new PDO('mysql:host=localhost;dbname=lookout', 'admin', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}

$pdo = connect();

// posts *******************************
$sql = 'SELECT * FROM `event` ORDER BY serial DESC';
$query = $pdo->prepare($sql);
$query->execute();
$rs_post = $query->fetchAll();

// The XML structure

$data .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$data .= '<channel>';

foreach ($rs_post as $row) {
$data .= '<item>';
$data .= '<time>'.$row['timestamp'].'</time>';
$data .= '<date>'.$row['timestamp'].'</date>';
$data .= '<location>'.$row['longitude'].'</location>';
$data .= '<report>'.$row['details'].'</report>';
$data .= '</item>';
}
$data .= '</channel>';
$data .= '</rss> ';

header('Content-Type: application/xml');
echo $data;
?>


There are no root tags missing, everything seems to be in order but obviously isn't.


No comments:

Post a Comment