Jump to content

Currency Conversion?


Perad

Recommended Posts

I am working on a website that has a price column and a currency column.

 

What I need to do is convert these to a single currency. This needs to be dynamic.. i.e. the database should remain unchanged.

 

Is there anyway to do this with MySQL?

 

Something Like.

 

SELECT price*1.5 FROM content WHERE currency='USD'

SELECT price*40 FROM content WHERE currency ='INR'

ORDER BY price ASC

 

If this cannot be done with MySQL does anyone have any ideas on the simplest way to achieve this with PHP?

Link to comment
https://forums.phpfreaks.com/topic/107284-currency-conversion/
Share on other sites

$currency = "USD";
$qry = mysql_query("SELECT price FROM content WHERE currency='".$currency."'";
list($price) = mysql_fetch_array($qry);

switch ($currency)
  {
    case "USD":
    $price = $price * 1.5;
    break;
    case "GBP":
    $price = $price * 2.0;
    break;
  }
echo $price;

Very vague example.

Link to comment
https://forums.phpfreaks.com/topic/107284-currency-conversion/#findComment-550079
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.