I have this code, where I try to get my most recent news stories and build an RSS feed. Right now it is writing to the ticker_items.xml file, but I am getting an error on the line "$xml_output .= "</items>\n";"
Here is the code:
<?
$file = 'ticker_items.xml';
include("xxxxxxxxx.php");
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query = "SELECT newsID, news_headline, news_date, news_author, REPLACE(news_headline, ' ', '-') AS news_headline_dashed FROM news ORDER BY news_date DESC LIMIT 5";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$file= fopen('ticker_items.xml' , 'w');
$xml_output = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n";
$xml_output = "<channel rdf:about=\"http://www.mysite.com/xml/\">\n";
$xml_output = "<title>MySite | My Site Title</title>\n";
$xml_output = "<link>http://www.mysite.com/?page=xml</link>\n";
$xml_output = "<description>My site description</description>\n";
$xml_output = "<items>\n";
$xml_output = "<rdf:Seq>\n";
for ($x = 0; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= "<rdf:li rdf:resource=\"http://www.mysite.com/" . $row['newsID'] . "/" . $row['news_headline_dashed'] . ".html\"/>\n";
}
$xml_output .= "</rdf:Seq>\n";
$xml_output .= "</items>\n";
$xml_output .= "</channel>\n";
for ($x = 0; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= "<item rdf:about=\"http://www.mysite.com/" . $row['newsID'] . "/" . $row['news_headline_dashed'] . ".html\">\n";
$xml_output .= "<dc:format>text/html</dc:format>\n";
$xml_output .= "<dc:source>http://www.mysite.com</dc:source>\n";
$xml_output .= "<dc:creator>MySite.com</dc:creator>\n";
$xml_output .= "<title>" . $row['news_headline'] . "</title>\n";
$xml_output .= "<link>http://www.mysite.com/" . $row['newsID'] . "/" . $row['news_headline_dashed'] . ".html</link>\n";
$xml_output .= "<description/>\n";
$xml_output .= "</item>\n";
}
$xml_output .= "</rdf:RDF>\n";
fputs($file, $xml_output);
fclose($file);
?>