Perad Posted May 26, 2008 Share Posted May 26, 2008 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 More sharing options...
papaface Posted May 26, 2008 Share Posted May 26, 2008 $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 More sharing options...
Barand Posted May 26, 2008 Share Posted May 26, 2008 SELECT (CASE currency WHEN 'USD' THEN price*1.5 WHEN 'INR' THEN price*40 ELSE price END) as price FROM content ORDER BY price Link to comment https://forums.phpfreaks.com/topic/107284-currency-conversion/#findComment-550080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.