Exchange Rates

r; } } } elseif (strcmp($to,"US") == 0) { $curquery = "SELECT " . $amount . "*1.0/rate AS r FROM exchange_rate WHERE date LIKE \"" . $year . "-" . $month . "%\" AND from_currency = \"US\" AND to_currency = \"" . $from . "\""; $curresults = mysql_query($curquery) or die("Currency query failed : " . mysql_error()); $num_cur = mysql_num_rows($curresults); if ($num_cur != 1) { echo "No data or incorrect query."; } else { while ($cur = mysql_fetch_object($curresults)) { $r_num = (float)$cur->r; } } } else { $firstquery = "SELECT " . $amount . "*1.0/rate AS r FROM exchange_rate WHERE date LIKE \"" . $year . "-" . $month . "%\" AND from_currency = \"US\" AND to_currency = \"" . $from . "\""; $firstresults = mysql_query($firstquery) or die("Currency query failed : " . mysql_error()); $num_first = mysql_num_rows($firstresults); if ($num_first != 1) { $num_cur == 0; } else { while ($first = mysql_fetch_object($firstresults)) { $first_r_num = $first->r; } $secondquery = "SELECT " . $first_r_num . "*rate AS r FROM exchange_rate WHERE date LIKE \"" . $year . "-" . $month . "%\" AND from_currency = \"US\" AND to_currency = \"" . $to . "\""; $secondresults = mysql_query($secondquery) or die("Currency query failed : " . mysql_error()); $num_second = mysql_num_rows($secondresults); if ($num_second != 1) { $num_cur == 0; echo "No data or incorrect query."; } else { while ($second = mysql_fetch_object($secondresults)) { $r_num = (float)$second->r; } $num_cur=1; } } } if ($num_cur == 1) { if (strcmp($acc,"2")==0) { printf('%7.2f',$r_num); } else { printf('%7.4f', $r_num); } } } $show = $_GET['show']; $from = $_GET['from']; $to = $_GET['to']; $month = $_GET['month']; $year = $_GET['year']; $amount = $_GET['amount']; $currencies = array("AU","TH","US","EU","UK","CN","JP"); $notes = array("AU dollars","baht","US dollars","euro","pounds","yuan","yen"); $names = array("Australia","Thailand","United States","Europe","United Kingdom","China","Japan"); $years=array("2009","2008","2007","2006"); $months=array("01","02","03","04","05","06","07","08","09","10","11","12"); $numCurrencies=7; reset($currencies); reset($notes); reset($months); reset($years); reset($names); if (strcmp($show,"history")==0) { $j = 0; $found = 0; foreach ($currencies as $i) { if (strcmp($i,$from)!=0) { if ($found == 0) { $j = $j+1; } } else { $found=1; } } foreach ($years as $y) { $nomore=1; echo '

' . $y . ", " . $notes[$j] . '

'; echo ''; echo ''; echo ''; foreach ($currencies as $c) { if (strcmp($c,$from)!=0) { echo ''; } } echo ''; for ($k = 11; $k >= 0; $k--) { if (strcmp(date("Y"),$y)==0) { if ((strcmp(date("m"),$months[$k])==0) or ($nomore==0)) { $nomore=0; } else { $nomore=1; } } else { $nomore=0; } if ($nomore == 0) { echo ''; echo ''; foreach ($currencies as $c) { if (strcmp($c,$from)!=0) { echo ''; } } echo ''; } } echo '
Month' . $c . '
' . monthAsString($months[$k]) . ''; convertCurrency(1.0,$from,$c,$months[$k],$y,0); echo '
'; } } elseif (strcmp($show,"current")==0) { $j = 0; $found = 0; foreach ($currencies as $i) { if (strcmp($i,$from)!=0) { if ($found == 0) { $j = $j+1; } } else { $found=1; } } echo '

As at ' . monthAsString($month) . ' ' . $year . ', ' . $amount . ' ' . $notes[$j] . ' was worth ...

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $j = 0; foreach ($currencies as $i) { if (strcmp($i,$from)!=0) { echo ''; echo ''; echo ''; echo ''; echo ''; } $j = $j + 1; } echo '
CurrencyRateValue
' . $i . ''; convertCurrency(1.0,$from,$i,$month,$year,0); echo ''; convertCurrency($amount,$from,$i,$month,$year,2); echo ' ' . $notes[$j]; echo '
'; echo 'Click on the country code to see historical exchange rates for that country'; } else { echo '

Currency Conversion

'; echo '

Historical Exchange Rates

'; echo 'Select a country/region to see the historical exchange rates to the other currencies:'; echo ''; echo '

Other Conversions

'; echo ''; } include 'dbclose.php'; ?>