<?php echo '<?xml version="1.0" encoding="utf-89" ?>'; ?>
<rss version="2.0">
<?php
mysql_connect('localhost', 'stigghg_buggh', 'zvovzmy');
	if (mysql_errno()) die("MySQL ERROR: ".mysql_errno().", ".mysql_error());
mysql_select_db('stigghg_healthbasic');
	if (mysql_errno()) die("MySQL ERROR: ".mysql_errno().", ".mysql_error());

$art = mysql_query("SELECT UNIX_TIMESTAMP(posted), scode, title, firstp FROM articles ORDER BY posted DESC LIMIT 0,10");
	if (mysql_errno()) die("MySQL ERROR: ".mysql_errno().", ".mysql_error());
?>
	<channel>
		<title>HealthBasic.org</title>
		<link>http://www.healthbasic.org</link>
		<description>Last 10 Updates</description>

<?php

while($art_array = mysql_fetch_array($art)){ 

		// Set title
	$art_title = $art_array['title'];

		// Set subtopic for link URL and category
	$sub = mysql_query("SELECT tcode, subtopic FROM subtopics WHERE scode='".$art_array['scode']."'");
		if (mysql_errno()) die("MySQL ERROR: ".mysql_errno().", ".mysql_error());
	$sub_array = mysql_fetch_array($sub);
	$sub_url = str_replace(" ", "_", $sub_array['subtopic']);
	$sub_url = strtolower($sub_url);
	$sub_cat = $sub_array['subtopic'];

		// Set topic for link URL and category
	$top = mysql_query("SELECT topic FROM topics WHERE tcode='".$sub_array['tcode']."'");
		if (mysql_errno()) die("MySQL ERROR: ".mysql_errno().", ".mysql_error());
	$top_array = mysql_fetch_array($top);
	$top_url = str_replace(" ", "_", $top_array['topic']);
	$top_url = strtolower($top_url);
	$top_cat = $top_array['topic'];

		// Set link
	$art_link = "http://healthbasic.org/".$top_url."/".$sub_url."/".substr($art_array['posted'], 2);

		// Set category
	$art_cat = $top_cat." > ".$sub_cat;

		// Set pubDate
	$art_pub = strftime("%a, %d %b %Y %T %H:%M:%S EST", $art_array['UNIX_TIMESTAMP(posted)']);

		// Set Description
	$art_desc = "<![CDATA[".trim($art_array['firstp'])."]]>";

?>
	<item>
		<title><?php echo $art_title;?></title>
		<link><?php echo $art_link;?></link>
		<category><?php echo $art_cat;?></category>
		<pubDate><?php echo $art_pub;?></pubDate>
		<description><?php echo $art_desc;?></description>
	</item>

<?php } ?>
	</channel>
</rss>