• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

Currency / Exchange Rate

Hi, my site allows users (marathon runners) to create a marathon profile page so that they can accept donations from their friends and families.

I have a section on the site called Charities, which shows the amount of money that each charity has received through the site.

The site currently allows users (donators) to donate in USD, EUR, GBP & AUD so each marathon profile page could have a mixture of donations from a mixture of currencies.

There are 30+ charities on my site that the marathon runners can choose to donate their money to at present.

Question
How do i control / calculate the overall total raised for a single charity as there will be a mixture of donations / currencies. A user can choose one of USD, EUR, GBP & AUD as their default currency view in their account, so i can just display the total in one of those, but how do i add all of the donations up.

I was thinking maybe it would be best to just convert all donations for the chosen charity into the users default currency using an exchange rate for each of the 4 available currencies and then manually changing the exchange rates on a daily basis (or pulling them from some exchange rate site)

How do you think this would be best handles, thanks in advance for your advice...
0
oo7ml
Asked:
oo7ml
3 Solutions
 
Julian HansenCommented:
You should keep a base currency for everything and then calculate relative to that - so if you store in dollars then total collected will be in dollars and at point of purchase you calc local currency version of dollar amount to deduct from entrant.

If you don't do it that way it is going to be a nightmare keeping everything in sync.
0
 
Ray PaseurCommented:
Agree with julianH; choose a "normalized" currency.  How are you receiving the payments?  If you're handling the money you will need to learn about PCI compliance.  Funds donated in one currency that need to be paid in another currency will incur exchange fees, which can be hefty.  Also, currency fluctuations will make a difference.  Consider this scenario:

1. Runner wants to run for a USA charity, but receives a donation in EUR.
2. If there is a time lag between the moment of the donation and the payment of the donation, a change in value between the USD and the EUR may potentially change the effective amount of the donation.
3. People may get emotional about this, demanding recompense from the money-handlers.

If you can set this up to use PayPal (so you do not handle the currency at all) you may save yourself a lot of headaches.  If you want to convert currencies yourself you may need something like this programming.  It's only a teaching sample and I do not endorse using it without the advice of your banking professionals.

<?php // RAY_currency_converter.php
error_reporting(E_ALL);

// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

class CurrencyConverter
{
    protected $error, $norml, $terse, $verbose, $array, $rates;
    protected static $currs;

    public function __construct()
    {
        // READ THE EXCHANGE RATES
        $url = 'http://www.99currencies.com/currency/curr.php';
        $str = file_get_contents($url);
        $str = str_replace(':CUR', NULL, $str);
        $this->rates = json_decode($str, TRUE);

        // DATA ADAPTED FROM XE.COM - SEE ALSO: http://en.wikipedia.org/wiki/ISO_4217
        $this->currs["AED"] = array("N" => "United Arab Emirates",                                 "C" => "Dirhams");
        $this->currs["AFN"] = array("N" => "Afghanistan",                                          "C" => "Afghanis");
        $this->currs["ALL"] = array("N" => "Albania",                                              "C" => "Leke");
        $this->currs["AMD"] = array("N" => "Armenia",                                              "C" => "Drams");
        $this->currs["ANG"] = array("N" => "Netherlands Antilles",                                 "C" => "Guilders (also called Florins)");
        $this->currs["AOA"] = array("N" => "Angola",                                               "C" => "Kwanza");
        $this->currs["ARS"] = array("N" => "Argentina",                                            "C" => "Pesos");
        $this->currs["AUD"] = array("N" => "Australia",                                            "C" => "Dollars");
        $this->currs["AWG"] = array("N" => "Aruba",                                                "C" => "Guilders (also called Florins)");
        $this->currs["AZN"] = array("N" => "Azerbaijan",                                           "C" => "New Manats");
        $this->currs["BAM"] = array("N" => "Bosnia and Herzegovina",                               "C" => "Convertible Marka");
        $this->currs["BBD"] = array("N" => "Barbados",                                             "C" => "Dollars");
        $this->currs["BDT"] = array("N" => "Bangladesh",                                           "C" => "Taka");
        $this->currs["BGN"] = array("N" => "Bulgaria",                                             "C" => "Leva");
        $this->currs["BHD"] = array("N" => "Bahrain",                                              "C" => "Dinars");
        $this->currs["BIF"] = array("N" => "Burundi",                                              "C" => "Francs");
        $this->currs["BMD"] = array("N" => "Bermuda",                                              "C" => "Dollars");
        $this->currs["BND"] = array("N" => "Brunei Darussalam",                                    "C" => "Dollars");
        $this->currs["BOB"] = array("N" => "Bolivia",                                              "C" => "Bolivianos");
        $this->currs["BRL"] = array("N" => "Brazil",                                               "C" => "Brazil Real");
        $this->currs["BSD"] = array("N" => "Bahamas",                                              "C" => "Dollars");
        $this->currs["BTN"] = array("N" => "Bhutan",                                               "C" => "Ngultrum");
        $this->currs["BWP"] = array("N" => "Botswana",                                             "C" => "Pulas");
        $this->currs["BYR"] = array("N" => "Belarus",                                              "C" => "Rubles");
        $this->currs["BZD"] = array("N" => "Belize",                                               "C" => "Dollars");
        $this->currs["CAD"] = array("N" => "Canada",                                               "C" => "Dollars");
        $this->currs["CDF"] = array("N" => "Congo/Kinshasa",                                       "C" => "Congolese Francs");
        $this->currs["CHF"] = array("N" => "Switzerland",                                          "C" => "Francs");
        $this->currs["CLP"] = array("N" => "Chile",                                                "C" => "Pesos");
        $this->currs["CNY"] = array("N" => "China",                                                "C" => "Yuan Renminbi");
        $this->currs["COP"] = array("N" => "Colombia",                                             "C" => "Pesos");
        $this->currs["CRC"] = array("N" => "Costa Rica",                                           "C" => "Colones");
        $this->currs["CUP"] = array("N" => "Cuba",                                                 "C" => "Pesos");
        $this->currs["CVE"] = array("N" => "Cape Verde",                                           "C" => "Escudos");
        $this->currs["CYP"] = array("N" => "Cyprus",                                               "C" => "Pounds (expires 2008-Jan-31)");
        $this->currs["CZK"] = array("N" => "Czech Republic",                                       "C" => "Koruny");
        $this->currs["DJF"] = array("N" => "Djibouti",                                             "C" => "Francs");
        $this->currs["DKK"] = array("N" => "Denmark",                                              "C" => "Kroner");
        $this->currs["DOP"] = array("N" => "Dominican Republic",                                   "C" => "Pesos");
        $this->currs["DZD"] = array("N" => "Algeria",                                              "C" => "Algeria Dinars");
        $this->currs["EEK"] = array("N" => "Estonia",                                              "C" => "Krooni");
        $this->currs["EGP"] = array("N" => "Egypt",                                                "C" => "Pounds");
        $this->currs["ERN"] = array("N" => "Eritrea",                                              "C" => "Nakfa");
        $this->currs["ETB"] = array("N" => "Ethiopia",                                             "C" => "Birr");
        $this->currs["EUR"] = array("N" => "Euro Member Countries",                                "C" => "Euro");
        $this->currs["FJD"] = array("N" => "Fiji",                                                 "C" => "Dollars");
        $this->currs["FKP"] = array("N" => "Falkland Islands (Malvinas)",                          "C" => "Pounds");
        $this->currs["GBP"] = array("N" => "United Kingdom",                                       "C" => "Pounds");
        $this->currs["GEL"] = array("N" => "Georgia",                                              "C" => "Lari");
        $this->currs["GGP"] = array("N" => "Guernsey",                                             "C" => "Pounds");
        $this->currs["GHS"] = array("N" => "Ghana",                                                "C" => "Cedis");
        $this->currs["GIP"] = array("N" => "Gibraltar",                                            "C" => "Pounds");
        $this->currs["GMD"] = array("N" => "Gambia",                                               "C" => "Dalasi");
        $this->currs["GNF"] = array("N" => "Guinea",                                               "C" => "Francs");
        $this->currs["GTQ"] = array("N" => "Guatemala",                                            "C" => "Quetzales");
        $this->currs["GYD"] = array("N" => "Guyana",                                               "C" => "Dollars");
        $this->currs["HKD"] = array("N" => "Hong Kong",                                            "C" => "Dollars");
        $this->currs["HNL"] = array("N" => "Honduras",                                             "C" => "Lempiras");
        $this->currs["HRK"] = array("N" => "Croatia",                                              "C" => "Kuna");
        $this->currs["HTG"] = array("N" => "Haiti",                                                "C" => "Gourdes");
        $this->currs["HUF"] = array("N" => "Hungary",                                              "C" => "Forint");
        $this->currs["IDR"] = array("N" => "Indonesia",                                            "C" => "Rupiahs");
        $this->currs["ILS"] = array("N" => "Israel",                                               "C" => "New Shekels");
        $this->currs["IMP"] = array("N" => "Isle of Man",                                          "C" => "Pounds");
        $this->currs["INR"] = array("N" => "India",                                                "C" => "Rupees");
        $this->currs["IQD"] = array("N" => "Iraq",                                                 "C" => "Dinars");
        $this->currs["IRR"] = array("N" => "Iran",                                                 "C" => "Rials");
        $this->currs["ISK"] = array("N" => "Iceland",                                              "C" => "Kronur");
        $this->currs["JEP"] = array("N" => "Jersey",                                               "C" => "Pounds");
        $this->currs["JMD"] = array("N" => "Jamaica",                                              "C" => "Dollars");
        $this->currs["JOD"] = array("N" => "Jordan",                                               "C" => "Dinars");
        $this->currs["JPY"] = array("N" => "Japan",                                                "C" => "Yen");
        $this->currs["KES"] = array("N" => "Kenya",                                                "C" => "Shillings");
        $this->currs["KGS"] = array("N" => "Kyrgyzstan",                                           "C" => "Soms");
        $this->currs["KHR"] = array("N" => "Cambodia",                                             "C" => "Riels");
        $this->currs["KMF"] = array("N" => "Comoros",                                              "C" => "Francs");
        $this->currs["KPW"] = array("N" => "Korea (North)",                                        "C" => "Won");
        $this->currs["KRW"] = array("N" => "Korea (South)",                                        "C" => "Won");
        $this->currs["KWD"] = array("N" => "Kuwait",                                               "C" => "Dinars");
        $this->currs["KYD"] = array("N" => "Cayman Islands",                                       "C" => "Dollars");
        $this->currs["KZT"] = array("N" => "Kazakhstan",                                           "C" => "Tenge");
        $this->currs["LAK"] = array("N" => "Laos",                                                 "C" => "Kips");
        $this->currs["LBP"] = array("N" => "Lebanon",                                              "C" => "Pounds");
        $this->currs["LKR"] = array("N" => "Sri Lanka",                                            "C" => "Rupees");
        $this->currs["LRD"] = array("N" => "Liberia",                                              "C" => "Dollars");
        $this->currs["LSL"] = array("N" => "Lesotho",                                              "C" => "Maloti");
        $this->currs["LTL"] = array("N" => "Lithuania",                                            "C" => "Litai");
        $this->currs["LVL"] = array("N" => "Latvia",                                               "C" => "Lati");
        $this->currs["LYD"] = array("N" => "Libya",                                                "C" => "Dinars");
        $this->currs["MAD"] = array("N" => "Morocco",                                              "C" => "Dirhams");
        $this->currs["MDL"] = array("N" => "Moldova",                                              "C" => "Lei");
        $this->currs["MGA"] = array("N" => "Madagascar",                                           "C" => "Ariary");
        $this->currs["MKD"] = array("N" => "Macedonia",                                            "C" => "Denars");
        $this->currs["MMK"] = array("N" => "Myanmar (Burma)",                                      "C" => "Kyats");
        $this->currs["MNT"] = array("N" => "Mongolia",                                             "C" => "Tugriks");
        $this->currs["MOP"] = array("N" => "Macau",                                                "C" => "Patacas");
        $this->currs["MRO"] = array("N" => "Mauritania",                                           "C" => "Ouguiyas");
        $this->currs["MTL"] = array("N" => "Malta",                                                "C" => "Liri (expires 2008-Jan-31)");
        $this->currs["MUR"] = array("N" => "Mauritius",                                            "C" => "Rupees");
        $this->currs["MVR"] = array("N" => "Maldives (Maldive Islands)",                           "C" => "Rufiyaa");
        $this->currs["MWK"] = array("N" => "Malawi",                                               "C" => "Kwachas");
        $this->currs["MXN"] = array("N" => "Mexico",                                               "C" => "Pesos");
        $this->currs["MYR"] = array("N" => "Malaysia",                                             "C" => "Ringgits");
        $this->currs["MZN"] = array("N" => "Mozambique",                                           "C" => "Meticais");
        $this->currs["NAD"] = array("N" => "Namibia",                                              "C" => "Dollars");
        $this->currs["NGN"] = array("N" => "Nigeria",                                              "C" => "Nairas");
        $this->currs["NIO"] = array("N" => "Nicaragua",                                            "C" => "Cordobas");
        $this->currs["NOK"] = array("N" => "Norway",                                               "C" => "Krone");
        $this->currs["NPR"] = array("N" => "Nepal",                                                "C" => "Nepal Rupees");
        $this->currs["NZD"] = array("N" => "New Zealand",                                          "C" => "Dollars");
        $this->currs["OMR"] = array("N" => "Oman",                                                 "C" => "Rials");
        $this->currs["PAB"] = array("N" => "Panama",                                               "C" => "Balboa");
        $this->currs["PEN"] = array("N" => "Peru",                                                 "C" => "Nuevos Soles");
        $this->currs["PGK"] = array("N" => "Papua New Guinea",                                     "C" => "Kina");
        $this->currs["PHP"] = array("N" => "Philippines",                                          "C" => "Pesos");
        $this->currs["PKR"] = array("N" => "Pakistan",                                             "C" => "Rupees");
        $this->currs["PLN"] = array("N" => "Poland",                                               "C" => "Zlotych");
        $this->currs["PYG"] = array("N" => "Paraguay",                                             "C" => "Guarani");
        $this->currs["QAR"] = array("N" => "Qatar",                                                "C" => "Rials");
        $this->currs["RON"] = array("N" => "Romania",                                              "C" => "New Lei");
        $this->currs["RSD"] = array("N" => "Serbia",                                               "C" => "Dinars");
        $this->currs["RUB"] = array("N" => "Russia",                                               "C" => "Rubles");
        $this->currs["RWF"] = array("N" => "Rwanda",                                               "C" => "Rwanda Francs");
        $this->currs["SAR"] = array("N" => "Saudi Arabia",                                         "C" => "Riyals");
        $this->currs["SBD"] = array("N" => "Solomon Islands",                                      "C" => "Dollars");
        $this->currs["SCR"] = array("N" => "Seychelles",                                           "C" => "Rupees");
        $this->currs["SDG"] = array("N" => "Sudan",                                                "C" => "Pounds");
        $this->currs["SEK"] = array("N" => "Sweden",                                               "C" => "Kronor");
        $this->currs["SGD"] = array("N" => "Singapore",                                            "C" => "Dollars");
        $this->currs["SHP"] = array("N" => "Saint Helena",                                         "C" => "Pounds");
        $this->currs["SLL"] = array("N" => "Sierra Leone",                                         "C" => "Leones");
        $this->currs["SOS"] = array("N" => "Somalia",                                              "C" => "Shillings");
        $this->currs["SPL"] = array("N" => "Seborga",                                              "C" => "Luigini");
        $this->currs["SRD"] = array("N" => "Suriname",                                             "C" => "Dollars");
        $this->currs["STD"] = array("N" => "S&atilde;o Tome and Principe",                         "C" => "Dobras");
        $this->currs["SVC"] = array("N" => "El Salvador",                                          "C" => "Colones");
        $this->currs["SYP"] = array("N" => "Syria",                                                "C" => "Pounds");
        $this->currs["SZL"] = array("N" => "Swaziland",                                            "C" => "Emalangeni");
        $this->currs["THB"] = array("N" => "Thailand",                                             "C" => "Baht");
        $this->currs["TJS"] = array("N" => "Tajikistan",                                           "C" => "Somoni");
        $this->currs["TMM"] = array("N" => "Turkmenistan",                                         "C" => "Manats");
        $this->currs["TND"] = array("N" => "Tunisia",                                              "C" => "Dinars");
        $this->currs["TOP"] = array("N" => "Tonga",                                                "C" => "Pa&apos;anga");
        $this->currs["TRY"] = array("N" => "Turkey",                                               "C" => "New Lira");
        $this->currs["TTD"] = array("N" => "Trinidad and Tobago",                                  "C" => "Dollars");
        $this->currs["TVD"] = array("N" => "Tuvalu",                                               "C" => "Tuvalu Dollars");
        $this->currs["TWD"] = array("N" => "Taiwan",                                               "C" => "New Dollars");
        $this->currs["TZS"] = array("N" => "Tanzania",                                             "C" => "Shillings");
        $this->currs["UAH"] = array("N" => "Ukraine",                                              "C" => "Hryvnia");
        $this->currs["UGX"] = array("N" => "Uganda",                                               "C" => "Shillings");
        $this->currs["USD"] = array("N" => "United States of America",                             "C" => "Dollars");
        $this->currs["UYU"] = array("N" => "Uruguay",                                              "C" => "Pesos");
        $this->currs["UZS"] = array("N" => "Uzbekistan",                                           "C" => "Sums");
        $this->currs["VEB"] = array("N" => "Venezuela",                                            "C" => "Bolivares (expires 2008-Jun-30)");
        $this->currs["VEF"] = array("N" => "Venezuela",                                            "C" => "Bolivares Fuertes");
        $this->currs["VND"] = array("N" => "Viet Nam",                                             "C" => "Dong");
        $this->currs["VUV"] = array("N" => "Vanuatu",                                              "C" => "Vatu");
        $this->currs["WST"] = array("N" => "Samoa",                                                "C" => "Tala");
        $this->currs["XAF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BEAC",   "C" => "Francs");
        $this->currs["XAG"] = array("N" => "Silver",                                               "C" => "Ounces");
        $this->currs["XAU"] = array("N" => "Gold",                                                 "C" => "Ounces");
        $this->currs["XCD"] = array("N" => "East Caribbean",                                       "C" => "Dollars");
        $this->currs["XDR"] = array("N" => "IMF Special Drawing Rights",                           "C" => "XDR");
        $this->currs["XOF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BCEAO",  "C" => "Francs");
        $this->currs["XPD"] = array("N" => "Palladium",                                            "C" => "Ounces");
        $this->currs["XPF"] = array("N" => "Comptoirs Fran&ccedil;ais du Pacifique Francs",        "C" => "CFP Francs");
        $this->currs["XPT"] = array("N" => "Platinum",                                             "C" => "Ounces");
        $this->currs["YER"] = array("N" => "Yemen",                                                "C" => "Rials");
        $this->currs["ZAR"] = array("N" => "South Africa",                                         "C" => "Rand");
        $this->currs["ZMK"] = array("N" => "Zambia",                                               "C" => "Kwacha");
        $this->currs["ZWD"] = array("N" => "Zimbabwe",                                             "C" => "Zimbabwe Dollars");

        // ELIMINATE THE MISMATCHED ITEMS
        $this->norml = $this->normalArrays();
        ksort($this->rates);
        ksort($this->currs);
    }

    public function getRates()
    {
        return $this->rates;
    }

    public function getCurrs()
    {
        return $this->currs;
    }

    public function getNormalization()
    {
        return $this->norml;
    }

    public function getError()
    {
        return $this->error;
    }

    public function asTerse()
    {
        return $this->terse;
    }

    public function asVerbose()
    {
        return $this->verbose;
    }

    public function asArray()
    {
        return $this->array;
    }

    public function normalArrays()
    {
        $response = NULL;
        foreach ($this->currs as $code => $x)
        {
            if (!isset($this->rates[$code]))
            {
                $response .= PHP_EOL . "$code IS IN CURRENCIES BUT NOT IN RATES";
                unset($this->currs[$code]);
            }
        }
        if ($response) $response .= PHP_EOL;
        foreach ($this->rates as $code => $x)
        {
            if (!isset($this->currs[$code]))
            {
                $response .= PHP_EOL . "$code IS IN RATES BUT NOT IN CURRENCIES";
                unset($this->rates[$code]);
            }
        }
        return $response;
    }

    public function isCurrency($code)
    {
        if (isset($this->rates[$code]))
        {
            return $this->rates[$code];
        }
        return FALSE;
    }

    public function convert($amount, $source_currency, $result_currency, $decimals=6)
    {
        // NORMALIZE DATA
        $this->array   = array();
        $this->error   = NULL;
        $this->terse   = NULL;
        $this->verbose = NULL;

        $source_currency = trim(strtoupper($source_currency));
        if (!isset($this->currs[$source_currency]))
        {
            $this->error .= "Currency $source_currency not found" . PHP_EOL;
        }

        $result_currency = trim(strtoupper($result_currency));
        if (!isset($this->currs[$result_currency]))
        {
            $this->error .= "Currency $result_currency not found" . PHP_EOL;
        }

        if ($this->error) return FALSE;

        // COMPUTE THE CONVERSION
        $rezult = 1.0 / $this->rates[$source_currency] * $this->rates[$result_currency] * $amount;

        //PREPARE THE RESPONSES
        $this->array
        = array
        ( "$source_currency" => number_format($amount, $decimals, '.', '')
        , "$result_currency" => number_format($rezult, $decimals, '.', '')
        )
        ;

        $this->terse
        = $this->array[$source_currency]
        . $source_currency
        . '='
        . $this->array[$result_currency]
        . "$result_currency"
        ;

        $this->verbose
        = $this->array[$source_currency]
        . ' '
        . $source_currency
        . ' ('
        . $this->currs[$source_currency]['N']
        . ' '
        . $this->currs[$source_currency]['C']
        . ')'
        . ' = '
        . $this->array[$result_currency]
        . ' '
        . $result_currency
        .' ('
        . $this->currs[$result_currency]['N']
        . ' '
        . $this->currs[$result_currency]['C']
        . ')'
        ;
        return (string)$rezult;
    }
}



// DEMONSTRATION SCRIPT
echo '<pre>';
$cc = new CurrencyConverter;


// IF A FORM WAS SUBMITTED
if (!empty($_GET))
{
    $getResult = $cc->convert($_GET['a'], $_GET['f'], $_GET['t']);

    // IF ANY ERROR OCCURRED
    if ($cc->getError()) echo PHP_EOL . $cc->getError();

    // SHOW THE THREE RETURN METHODS
    echo PHP_EOL . $cc->asTerse();
    echo PHP_EOL . $cc->asVerbose();
    echo PHP_EOL;  var_dump($cc->asArray());
}



// SEE WHAT IS MISSING FROM THE CONVERTER
echo $cc->getNormalization();
echo PHP_EOL;


// TRY THE SPOT PRICE OF AN OUNCE OF GOLD
$gold = $cc->convert
( 1.0   // AMOUNT TO CONVERT
, 'XAU' // CONVERT FROM TROY OUNCES OF GOLD
, 'USD' // EXPRESS ANSWER IN US DOLLARS
, 2     // TO TWO DECIMAL PLACES
)
;

// IF ANY ERROR OCCURRED
if ($cc->getError())
{
    echo PHP_EOL . $cc->getError();
}
else
{
    echo PHP_EOL . 'THE PRICE OF GOLD IS $' . number_format($gold,2);
}
echo PHP_EOL;



// CONVERT 3 BRITISH POUNDS TO US DOLLARS
echo PHP_EOL
. $cc->convert
( 3.0   // AMOUNT TO CONVERT
, 'gbp' // CONVERT FROM POUNDS STERLING
, 'usd' // INTO US DOLLARS
, 2     // TO TWO DECIMAL PLACES
)
;

// IF ANY ERROR OCCURRED
if ($cc->getError()) echo PHP_EOL . $cc->getError();

// SHOW THE THREE RETURN METHODS
echo PHP_EOL . $cc->asTerse();
echo PHP_EOL . $cc->asVerbose();
echo PHP_EOL;  var_dump($cc->asArray());
echo PHP_EOL;



// SHOW ERROR HANDLING - CONVERT 2 FOOS TO BARS
echo PHP_EOL . $cc->convert(2, 'Foo', 'Bar');

// IF ANY ERROR OCCURRED
if ($cc->getError()) echo PHP_EOL . $cc->getError();

// SHOW THE THREE RETURN METHODS
echo PHP_EOL . $cc->asTerse();
echo PHP_EOL . $cc->asVerbose();
echo PHP_EOL;  var_dump($cc->asArray());
echo PHP_EOL;



// CREATE A FORM FOR THE CLIENT
echo '<form>';

echo 'AMOUNT TO CONVERT: ';
echo '<input name="a" />';

echo '<br/>CHOOSE "FROM" CURRENCY';
echo '<br/><select name="f">' . PHP_EOL;
echo '<option value="NUL" selected="selected">CHOOSE CURRENCY</option>' . PHP_EOL;
foreach ($cc->getCurrs() as $code => $arr)
{
    echo '<option value="';
    echo $code;
    echo '">';
    echo $arr['N'];
    echo ' ';
    echo $arr['C'];
    echo '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

echo '<br/>CHOOSE "TO" CURRENCY';
echo '<br/><select name="t">' . PHP_EOL;
echo '<option value="NUL" selected="selected">CHOOSE CURRENCY</option>' . PHP_EOL;
foreach ($cc->getCurrs() as $code => $arr)
{
    echo '<option value="';
    echo $code;
    echo '">';
    echo $arr['N'];
    echo ' ';
    echo $arr['C'];
    echo '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

echo '<input type="submit" />';
echo '</form>';

// SHOW THE CURRENCIES WE HAVE IN THE OBJECT
print_r($cc->getCurrs());

// SHOW THE RATES WE HAVE IN THE OBJECT
print_r($cc->getRates());

Open in new window

Best of luck with it, ~Ray
0
 
X-treemCommented:
I would keep the values in separate fields in the table and give an overview from the different currencies in the total page of each runner.

then calculate an approximate total based on the currency rates of a specific moment.
after all, when you need to pay the amount to the runner, the currencies have to be converted at that time using the rate of that moment which can be different from your calculation.
0
 
oo7mlAuthor Commented:
Thanks for all of the replies guys and sorry about the late reply...

I was thinking it would probably be best to only accept donations in the currency that the marathon runner set the profile page up as...

So, for example, if they set it up as $ and a user from Europe wanted to donate, the could choose $5 but then PayPal would work out there and then what it is actually costing them in €

Then on top of this, i can use a base currency for the site too... what you reckon...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now