Forum Moderators: coopster
Any ideas?
<?php
include("DBConnection.php");
// open a file pointer to an RSS file
$fp = fopen ("rss_mixes.xml", "w");
// Now write the header information
fwrite ($fp, "<?xml version='1.0'?><rss version='2.0'><channel>");
fwrite ($fp, "<title>Tester</title>");
fwrite ($fp, "<link>http://www.example.co.uk/</link>");
fwrite ($fp, "<description>Tester</description>");
fwrite ($fp, "<language>en-us</language>");
fwrite ($fp, "<docs>http://www.example.co.uk/rss_mixes.xml</docs>");
$sSQL = "SELECTdistinct mixname,
Mixes.DJ
FROMMixes
WHEREMixes.Visible = 1
ORDER BYMixes.MixID DESC";
$content_result = mysql_query($sSQL) or trigger_error(mysql_error());
while ($content_rec = mysql_fetch_row($content_result)) {
fwrite ($fp, "<item>");
$headline = $content_rec[0]; fwrite ($fp, "</item>"); fwrite ($fp, "</channel></rss>"); ?> [1][edited by: bill at 2:35 am (utc) on Feb. 2, 2007]
$content_1 = substr($content_rec, 0, 250);
$content = strip_tags($content_1);
if (strlen($content_rec[1]) > 250) {
$content = $content . "....";
}
fwrite ($fp, "<title>$headline</title>");
fwrite ($fp, "<description>Mixed by $content</description>");
$item_link = "http://www.example.co.uk/Mixes/$content_rec[3]";
fwrite ($fp, "<link>$item_link</link>");
}
fclose ($fp);
[edit reason] Use "example" for domain name [/edit]
$item_link = "http://www.example.co.uk/Mixes/$content_rec[3]";
Which isn't properly constructed. It should be either one of the following:
$item_link = "http://www.example.co.uk/Mixes/{$content_rec[3]}";
# or
$item_link = "http://www.example.co.uk/Mixes/".$content_rec[3];
If you are having trouble validating the XML part, and aren't getting any PHP errors, then I'd suggest you run the script, then view the resulting xml file for xml-specific errors. I am not too familiar with xml validation, so I'll let someone else take it from here :)
Good luck!
$content_1 = substr($content_rec, 0, 250);
Can you spot it? ;) $content_rec is an array here, not a string. I think you were meaning to make it something like this:
#Now it is referencing an element of the array; not the array itself.
$content_1 = substr([b]$content_rec[1][/b], 0, 250);
Now let's see if we can spot some xml errors :)