<?
header('Content-type: text/xml');
// forbindelse til database
$host = "localhost";
$db = "nyhed";
$user = "root";
$password = "password";
$connection = mysql_pconnect($host, $user, $password) or trigger_error(mysql_error(),E_USER_ERROR);
$rssdato = strtotime("now"); // hent dato
$rssdate = strftime("%a, %d %b %Y %H:%M:%S"); // format tid
// Send out the header
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
";
?>
<rss version="2.0">
<channel>
<title>Thor online</title>
<link>
http://localhost/to2/</link><description>Thor online nyeste artikler</description>
<pubDate><? echo $rssdate; ?> (GMT) +0100 </pubDate>
<lastBuildDate><? echo $rssdate; ?> (GMT) +0100 </lastBuildDate>
<language>da</language>
<copyright>Copyright (c) 2006 Thor online</copyright>
<image>
<title>Thor online</title>
<width>144</width>
<height>18</height>
<link>
http://localhost/to2/</link><url>
http://localhost/to2/rss/rss.jpg</url>
</image>
<?php
// connect and query database
mysql_select_db($db, $connection);
// Query db - sort showing the 5 most recent
$query = "SELECT imglille,id, overskrift, nyhed, dato AS Date FROM nyheder ORDER BY dato DESC LIMIT 20";
$rs = mysql_query($query, $connection) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
do
{
// get values from database about articles
$id = $row_rs['id']; // Unique ID
$title = $row_rs['overskrift']; // Title of article
$body = stripslashes($row_rs['nyhed']); // Description
$tegn = "200";
$felt = substr($body, 0, $tegn);
$pic = $row_rs['imglille'];
// get published date
$rssdate = $row_rs['Date'];
$sql_date = mysql_query("SELECT date_format(dato, '%a, %e %b %Y %T') as date FROM nyheder WHERE id='$row_rs[id]'") or die (mysql_error());
$rssdate = mysql_fetch_row($sql_date);
?>
<item>
<title><? echo "$title"; ?></title>
<link>
http://localhost/to2/vis3.php?id=<?php echo "$id"; ?></link>
<pubDate><?php echo "$rssdate[0] +0100 (CET)"; ?></pubDate>
<description><![CDATA[<p><a href="
http://localhost/to2/vis3.php?id=<?php echo "$id"; ?>"<img src="
http://localhost/to2/img/<? echo "$pic" ?>" align="left" width="85" height="85" border="0"></a> <? echo "$felt .......</p>"; ?><br clear=all>]]></description>
<guid>
http://localhost/to2/vis3.php?id=<?php echo "$id"; ?></guid>
</item>
<?php
} while ($row_rs = mysql_fetch_assoc($rs));
// close connection
mysql_free_result($rs);
?>
</channel>
</rss>