<?php header('Content-type: text/xml'); ?>
<?php
	echo("<rss version=\"2.0\">
	"); ?>
<?php include("names.php"); ?>
<?php
$dbh=mysql_connect ("localhost", $names_database_user, $names_database_password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($names_database_name);

$date_query = "SELECT MAX(entry_date) max_entry_date
	FROM main_entry 
	WHERE keywords LIKE '%$main_keyword%' COLLATE latin1_swedish_ci  
		OR keywords LIKE '%public%'  COLLATE latin1_swedish_ci"; 
 
$date_result = mysql_query($date_query);	

 while($date_row = mysql_fetch_array($date_result)){
    $latest_publish_date = $date_row[max_entry_date];
	};
echo("
	<channel>
    <title>Marc Durham's Webpage</title>
    <link>http://$names_site_name/</link>
    <description>Marc Durham's Webpage, Blogs, Travels, and Bookmarks.</description>
    <language>en-us</language>
    <pubDate>$latest_publish_date -0800</pubDate>
    <lastBuildDate>$latest_publish_date -0800</lastBuildDate>
    <docs>http://$names_site_name/rss</docs>
    <generator>Notepad Plus Plus and PHP</generator>
    <managingEditor>rss@marcdurham.com (Marc Durham)</managingEditor>
    <webMaster>webmaster@marcdurham.com (Marc Durham)</webMaster>
    <ttl>15</ttl>
 ");
 
 $entry_query = "SELECT entry_date, DATE_FORMAT(entry_date, '%Y-%m-%d %W %H:%i') AS entry_date_f, 
	entry_id, subject, entry_text 
	FROM main_entry 
	WHERE keywords LIKE '%$main_keyword%' COLLATE latin1_swedish_ci  
		OR keywords LIKE '%public%'  COLLATE latin1_swedish_ci
	ORDER BY entry_date DESC LIMIT 10"; 

$entry_result = mysql_query($entry_query);
	
 while($entry_row = mysql_fetch_array($entry_result)){
    $entry_id = $entry_row[entry_id];
	$subject = $entry_row[subject];
	$entry_date = $entry_row[entry_date];
	$entry_text = $entry_row[entry_text];
	$sub_entry_text = substr($entry_text,0,100);
   
	echo("
    <item>
      <title>$subject</title>
      <link>http://$names_site_name/entry_$entry_id</link>
      <description>$subject</description>
      <pubDate>$entry_date -0800</pubDate>
      <guid>http://$names_site_name/entry_$entry_id</guid>
    </item> ");
	
	}
echo("	
  </channel> ");
  ?>
</rss>

