fazzfarrell Posted September 22, 2006 Share Posted September 22, 2006 I have built a shopping cart site with php, that works fine but now the customer wants the user to be able to change the currency from GBP to other currencies.I have looked for solutions but can not find any, can any one point me in the right direction?thanks Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/ Share on other sites More sharing options...
steveclondon Posted September 22, 2006 Share Posted September 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96705 Share on other sites More sharing options...
fazzfarrell Posted September 22, 2006 Author Share Posted September 22, 2006 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 448I can't see why it is doing this? any ideas Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96720 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96725 Share on other sites More sharing options...
fazzfarrell Posted September 22, 2006 Author Share Posted September 22, 2006 Thanks tried this but nothing happens! Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96738 Share on other sites More sharing options...
akitchin Posted September 22, 2006 Share Posted September 22, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96742 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 My code should work. I tested it before posting? Do you get any errors or what happens? Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96744 Share on other sites More sharing options...
fazzfarrell Posted September 22, 2006 Author Share Posted September 22, 2006 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 Selectorif ($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";?> Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96754 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 But the dropdown list does show correctly, right? Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96756 Share on other sites More sharing options...
fazzfarrell Posted September 22, 2006 Author Share Posted September 22, 2006 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 isI have the GBP prices in a database they are the default prices on the siteI 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? Quote Link to comment https://forums.phpfreaks.com/topic/21662-currency-converter/#findComment-96762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.