Jump to content

currency converter


fazzfarrell

Recommended Posts

you need to have a list of currencies in mysql with exchange rates each should have a batch id as these exchange rates will change. All exchange rates should be against the dollar, you can get these from xe.com.

Then you need to test the currency that the user has and pull the latest batch id currency from the currency that they want to convert into. Then use this to calcuate your new currency and x the amount by this value. You will need to do some formating on the result after as you may well have the odd amount of the point after.
Link to comment
Share on other sites

Thanks,

I have entered this code:

<select name="curr" style="width:150px">
                  <option value="USD" <?php ($HTTP_SESSION_VARS["icJag"]->DisplayCurrency == "USD") ? echo "SELECTED": echo ""; ?>>US Dollar (USD)</option>
                  <option value="EUR" <?php ($HTTP_SESSION_VARS["icJag"]->DisplayCurrency == "EUR") ? echo "SELECTED": echo ""; ?>>Euro (EUR)</option>
                  <option value="GBP" <?php ($HTTP_SESSION_VARS["icJag"]->DisplayCurrency == "GBP") ? echo "SELECTED": echo ""; ?>>British Pound (GBP)</option>
                </select>

Which should convert the currency symbol but I am getting this error: Parse error: parse error, unexpected T_ECHO in /home/sites/jaguar.com/public_html/results2.php on line 448


I can't see why it is doing this? any ideas
Link to comment
Share on other sites

[code]<?php
$currencies = array(
'usd' => "US Dollar",
'eur' => "Euro",
'gbp' => "British Pound",
);

echo "<select name='curr' style='width:150px'>\n";
foreach($currencies as $short => $long)
{
$short = strtoupper($short);
$selected = $_SESSION['icJag']->DisplayCurrency == $short ? "selected='selected'" : null;
echo "\t<option value='{$short}'{$selected}>{$long} ({$short})</option>\n";
}
echo "</select>\n";
?>
[/code]
Link to comment
Share on other sites

in order to use the ternary operator as you are in your original code (Daniel0's should have fixed that problem), you need to start with a command as far as i know.  if you're going to start with an if() statement, why bother using the ternary?

in order to correct your original code, you'd need to change your lines to this:

[code]<option value="USD" <?php echo ($HTTP_SESSION_VARS["icJag"]->DisplayCurrency == "USD") ? 'SELECTED' : ''; ?>>US Dollar (USD)</option>[/code]

that being said, Daniel0's code is much cleaner, and i'd suggest using that.  what do you mean by "nothing happens"?  no select box, an empty select box, shoddy HTML output, or what?
Link to comment
Share on other sites

Im lost now!

this is my full page code, but when I select basicly nothing happens on the page other than price totals revert to '0.00'

I think i am missing something!


<?php
// IntelliCART MX - Country Code Selector
if ($HTTP_POST_VARS["curr"] != $HTTP_SESSION_VARS["icJag"]->DisplayCurrency) {
$HTTP_SESSION_VARS["icJag"]->DisplayCurrency = $HTTP_POST_VARS["curr"];
}
?>

then for the drop downs

<?php
$currencies = array(
'usd' => "US Dollar",
'eur' => "Euro",
'gbp' => "British Pound",
);

echo "<select name='curr' style='width:150px'>\n";
foreach($currencies as $short => $long)
{
$short = strtoupper($short);
$selected = $_SESSION['icJag']->DisplayCurrency == $short ? "selected='selected'" : null;
echo "\t<option value='{$short}'{$selected}>{$long} ({$short})</option>\n";
}
echo "</select>\n";
?>
Link to comment
Share on other sites

Yes it now displays correctly great!

But I can not get the currency on screen to change to $ etc. What I am trying to do is

I have the GBP prices in a database they are the default prices on the site

I want a drop down wih the other currencies that can be chosen.

When ou select say 'USD' the price and '£' change to the dollar conversion through to payment.

Does that make sense?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.