Lookup Currency Rates
Product UPDATE desc_item';
} else { echo '
Error DELETE central.currency_rates: ' . mysql_error() . '
'; }
$periods = @mysql_query("SELECT cur_id, code FROM central.currency WHERE cur_id!='$from_cur_id'");
if (!$periods) { exit('
Error retrieving parts from database!
' . 'Error: ' . mysql_error() . '
'); }
while ($period = mysql_fetch_array($periods)) {
$to_cur_id = $period[0];
$to_code = $period[1];
$ch = curl_init();
$ag = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 GTB7.1 ( .NET CLR 3.5.30729)";
curl_setopt($ch, CURLOPT_USERAGENT, $ag);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_URL,"http://rate-exchange.appspot.com/currency?from=$from_code&to=$to_code");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
//curl_close ($ch);
$pieces = explode("\n", $result);
echo print_r($pieces);
if (count($pieces) > 0) {
$line = $pieces[9];
//echo "pieces[9]: $pieces[9]";
preg_match('@(.*) ([0-9]+\.[0-9]+),(.*)@', $line, $matches);
$rate = $matches[2];
//echo " rate: $rate
";
}
curl_close ($ch);
$sql = "INSERT INTO central.currency_rates SET from_cur_id='$from_cur_id', to_cur_id='$to_cur_id', rate='$rate'";
if (@mysql_query($sql)) { //echo '
Product UPDATE desc_item
';
} else { echo '
Error INSERT central.currency_rates: ' . mysql_error() . '
'; }
}
?>