Forum Moderators: open
I'm starting the rss file with:
<?xml version='1.0'?>
<rss version='2.0'>
And then the channel info, then the php to create the item info (pulled from mysql). Then closing the channel & rss.
This validates, but when viewed in a browser, the php info is visible rather than the items. When added to an aggragator (my yahoo), only the channel info is visible. Any ideas on what I'm doing wrong? Thanks!
You may need to do a little work to make your server handle the php as "php" becase your file is rss you might need to alter your mime type to let php work within an .rss extension.
E.g. Putting this in an .htaccess file in the same folder as "feed.xml" would force the webserver to parse the file as php
<Files feed.xml>
ForceType application/x-httpd-php
</Files>
header('Content-Type: text/xml');echo '<?xml version='1.0'?>'
echo '<rss version='2.0'>'
echo '<channel>'
echo '<title>Example.com Test RSS 2</title>'
echo '<description>Anytown Widgets and more! Click for The County's Internet Marketplace.</description>'
echo '<link>http://www.example.com/</link>'
echo '<copyright>Copyright 1998 - 2004 example.com. All Rights Reserved</copyright>'
<?php
include("../admin/config.php");
$sql = "SELECT category, adtext, id FROM classifieds WHERE postdate >= NOW() - INTERVAL 2 DAY AND status = 'a' ORDER BY RAND() DESC LIMIT 3";
$result = mysql_query($sql, $conn) or die (mysql_error());
//GO THROUGH EACH ROW IN THE RESULT AND DISPLAY DATA
while ($newArray = mysql_fetch_array($result)) {
//give a name to the fields
$category = $newArray['category'];
$adtext = $newArray['adtext'];
$id = $newArray['id'];
//WRITE ITEM INFO
fwrite ($fp, "<title>$category</title>");
fwrite ($fp, "<description>$adtext</description>");
fwrite ($fp, "<link>$id</link>");
fwrite ($fp, "<item>$item</item>");
}
?>
echo '</channel>'
echo '</rss>'
The error I'm getting is "invalid at the top level of the document.
[edited by: werty at 8:48 am (utc) on Dec. 26, 2004]
[edit reason] Removed URL, Widgitized the description, changed domain to example.com. [/edit]
Hope this works for you
John