Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. // Add this to impvars.php:
  2.  
  3.   // Calculator, default currencies in ISO code
  4.   $from_currency = 'USD';
  5.   $target_currency = 'NOK';
  6.  
  7. // Below are the new contents of calculator.php, simply replace all of it
  8. <?
  9. require_once('impvars.php');
  10. $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  11. ?>
  12. <script type="application/javascript">
  13. function UpdateCurrency()
  14. {
  15.     var amount = document.getElementById('amount');
  16.     var from = document.getElementById('from');
  17.     var target = document.getElementById('target');
  18.     var targetvalue = target.options[target.selectedIndex].value;
  19.     var fromvalue = from.options[from.selectedIndex].value;
  20.     <?
  21.     $queryjs = "SELECT currency_USD FROM currencies";
  22.     $datajs = mysqli_query($dbc, $queryjs);
  23.     $rowjs = mysqli_fetch_array($datajs);
  24.     $USD = $rowjs['currency_USD'];
  25.     ?>
  26.     if (fromvalue == <?=$USD?>)
  27.     {
  28.         converted = amount.value * targetvalue;
  29.     }
  30.     else
  31.     {
  32.         var convertedhalf = amount.value / fromvalue;
  33.         converted = convertedhalf * targetvalue;
  34.     }
  35.     document.getElementById('convertedmoney').innerHTML= amount.value + ' ' + from.options[from.selectedIndex].innerHTML + ' = ' + converted + ' ' + target.options[target.selectedIndex].innerHTML;
  36. }
  37. </script>
  38. <?
  39. $query = "SELECT * FROM currencies";
  40. $data2 = mysqli_query($dbc, $query);
  41. $row2 = mysqli_fetch_array($data2);
  42. $query = "SELECT * FROM currencies_names";
  43. $data3 = mysqli_query($dbc, $query);
  44. $row3 = mysqli_fetch_array($data3);
  45. $currentcolumn = "currency_AFN";
  46. ?>
  47. <strong>Amount</strong>
  48. <input type="text" id="amount" onChange="UpdateCurrency()" />
  49. <br />
  50. <strong>From</strong>
  51. <select id="from" onChange="UpdateCurrency()">
  52. <?
  53. $query = "SELECT * FROM currencies_abbr";
  54. $data = mysqli_query($dbc, $query);
  55. while ($row = mysqli_fetch_array($data)) {
  56. $currentcolumn = "currency_" . $row['abbrevation'];
  57. if(!empty($row3[$currentcolumn]) && !empty($row2[$currentcolumn]))
  58.     {
  59.         if ($row['abbrevation'] == $from_currency) {
  60.             ?>
  61.     <option value="<? echo $row2[$currentcolumn]; ?>" selected><? echo $row3[$currentcolumn];  ?></option>
  62.             <?
  63.         }
  64.         else {
  65.     ?>
  66.     <option value="<? echo $row2[$currentcolumn]; ?>"><? echo $row3[$currentcolumn];  ?></option>
  67.     <?
  68.         }
  69.     }
  70. }
  71. ?>
  72. </select>
  73. <strong>To</strong>
  74. <select id="target" onChange="UpdateCurrency()">
  75. <?
  76. $query = "SELECT * FROM currencies_abbr";
  77. $data = mysqli_query($dbc, $query);
  78. while ($row = mysqli_fetch_array($data)) {
  79. $currentcolumn = "currency_" . $row['abbrevation'];
  80. if(!empty($row3[$currentcolumn]) && !empty($row2[$currentcolumn]))
  81.     {
  82.         if ($row['abbrevation'] == $target_currency) {
  83.             ?>
  84.             <option value="<? echo $row2[$currentcolumn]; ?>" selected><? echo $row3[$currentcolumn];  ?></option>
  85.             <?
  86.         }
  87.         else {
  88.     ?>
  89.     <option value="<? echo $row2[$currentcolumn]; ?>"><? echo $row3[$currentcolumn];  ?></option>
  90.     <?
  91.         }
  92.     }
  93. }
  94. mysqli_close($dbc);
  95. ?>
  96. </select>
  97.    
  98. <br />
  99. <span id="convertedmoney"></span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement