Here you go. Actually, the more I look at this, I see a lot of optimizations to be made. I wrote this before I totally understood SQL.
Code: <?php
[Mysql connection code removed for security purposes]
$sql = "SELECT * FROM table_articles";
if ( !($result = $mdb->sql_query($sql)) )
{
echo 'DB Access Error!<BR>';
exit;
}
$totallines = mysql_num_rows($result);
header('Content-type: text/xml');
print('<?xml version="1.0" encoding="iso-8859-1" ?>');
print('<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:annotate="http://purl.org/rss/1.0/modules/annotate/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!--
This feed generated for Cemetech by CemetechNews
-->
<channel>
<title>Cemetech</title>
<link>http://www.cemetech.net/</link>
<description>Leading the Way to the Future</description>
<managingEditor>kerm_martian@yahoo.com</managingEditor>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>RSS Feed 2.2.1</generator>
<language>en</language>
<lastBuildDate>');
echo date('D, d M Y H:i:s') . ' CST';
print('</lastBuildDate>
<image>
<url>http://www.cemetech.net/img/logo/cemetech.gif</url>
<title>Cemetech</title>
<link>http://www.cemetech.net/</link>
<width>236</width>
<height>37</height>
</image>');
$count = 0;
$sql = "SELECT * FROM table_articles";
if ( !($result = $mdb->sql_query($sql)) )
{
echo 'DB Access Error!<BR>';
exit;
}
while (($count != 4) && ($row = $mdb->sql_fetchrow($result))) {
$newsID = $row['newsID'];
Display_Article($row['title'],$row['timestamp'],$row['discusslink'],$row['text'],"http://www.cemetech.net/news.shtml?$newsID");
//Display_Article($curnewsarray[0],$curnewsarray[1],$curnewsarray[2],$curnewsarray[3],"http://www.cemetech.net/news.shtml?$numlink");
$count++;
}
print('</channel></rss>');
exit;
function Display_Article($atitle,$adate,$adiscusslink,$atext,$apermlink)
{
print('<item><title>');
$atitle = xmlclip($atitle);
print($atitle);
print('</title><link>');
$apermlink = xmlclip($apermlink);
print($apermlink);
print('</link>');
print('<pubDate>');
$adate = sqltotime($adate);
$adate = date('D, d M Y H:i:s',$adate) . ' CST';
$adate = xmlclip($adate);
print($adate);
print('</pubDate>');
print('<guid isPermaLink="true">');
print($apermlink);
print('</guid><description>');
$atext = xmlclip($atext);
print($atext);
print('</description><dc:creator>Kerm Martian</dc:creator><dc:subject>');
print($atitle);
print('</dc:subject></item>');
}
function xmlclip($a) {
$a = str_replace('&','&',$a);
$a = str_replace('"','"',$a);
$a = str_replace('<','<',$a);
$a = str_replace('>','>',$a);
$a = str_replace(' ',' ',$a);
$a = str_replace(' ',' ',$a);
return $a;
}
function sqltotime($a)
{
$year = substr($a, 0, 4);
$month = substr($a, 5, 2);
$day = substr($a, 8, 2);
return mktime(0, 0, 0, $month, $day, $year);
}
?>