<?php header("Content-Type: application/xml");  ?>
<?php printf('<?xml version="1.0" encoding="iso-8859-1"?> '); ?>

<?php
require_once('Connections/watches.php');
require_once('includes/functions.inc.php');
function rssTime($dt) { 
    $yr=strval(substr($dt,0,4)); 
    $mo=strval(substr($dt,5,2)); 
    $da=strval(substr($dt,8,2)); 
    $hr=strval(substr($dt,11,2)); 
    $mi=strval(substr($dt,14,2)); 
    return date("D, d M Y H:i:s", mktime ($hr,$mi,0,$mo,$da,$yr))." 3600"; 
} 

// begin Recordset
$query_bestsellingwatches = "SELECT orders_products.products_id, SUM( orders_products.products_quantity ) AS totalSold, products.products_model, products.products_image, products.products_price, products_description.products_name, products_description.products_description FROM orders_products, orders, products, products_description WHERE products.products_price > 20 AND orders.orders_id = orders_products.orders_id AND products.products_id = orders_products.products_id AND orders_products.products_id = products_description.products_id AND DATE_SUB( CURDATE( ) , INTERVAL 60 DAY ) <= orders.date_purchased AND products_description.language_id =1 AND products.products_status=1 AND orders.orders_status = 3 GROUP BY orders_products.products_id ORDER BY totalSold DESC  LIMIT 0 , 10";
$bestsellingwatches = $watches->SelectLimit($query_bestsellingwatches) or die($watches->ErrorMsg());
$totalRows_bestsellingwatches = $bestsellingwatches->RecordCount();
// end Recordset

 //PHP ADODB document - made with PHAkt 2.0.60
 
function feedDesc($text) { 
	$text = str_replace(" & "," and ",$text);
	$text = str_replace("’","'",$text);
	$text = strip_tags($text);
	$text = str_replace("?","",$text);
	$text = str_replace("£","",$text);
	$text = str_replace("&pound;","",$text);
	$text = str_replace("?","",$text);
	$text = str_replace("  ? "," ",$text);
	
	return $text; 
}
 
 
?>



<rss version="2.0">
   <channel>
      <title>Find Watches Current Best Sellers</title>
      <link>http://www.findwatches.co.uk</link> 
	  <description>Current best selling watches from Find Watches</description>
	  <pubDate><?php echo date("D, d M Y H:i:s",time())." 3600"; ?></pubDate>
		
		<?php // repeat
		  while (!$bestsellingwatches->EOF) {
		?>
		
		
			<item> 
				<title><?php echo str_replace("&","and",$bestsellingwatches->Fields('products_name')); ?></title>
				<link>http://www.findwatches.co.uk/product_info.php?products_id=<?php echo $bestsellingwatches->Fields('products_id'); ?></link>
				<description><?php echo feedDesc($bestsellingwatches->Fields('products_description')); ?></description>
				<guid isPermaLink="true">http://www.findwatches.co.uk/product_info.php?products_id=<?php echo $bestsellingwatches->Fields('products_id'); ?></guid>
			</item>



<?php
    $bestsellingwatches->MoveNext();
  }
?>
</channel>
  </rss>