Mal1 Posted August 3, 2012 Share Posted August 3, 2012 I'm using a script which converts currency between GBP and EUR and USD etc and uses up to date exchange rates and it's working fine. But I want to display prices based on which option the user selects (e.g. using flags). Right now I'm having to display each currency I want to display one under the other but am looking to be able to select a flag and it to only use the code/div/span for that currency. Not sure which type of code this would be? Any pointers to similar code? I'm a complete self-taught beginner but I'm pretty confident that I'd be able to modify a similar piece of code to my needs. Could I do something whereby the flags add something to the URL then the Divs are echoed or not echoed based on what is contained in the URL. ***Whatever I use would need to be permanent (into the URL or something) so that all the prices on the website are converted not just one page.*** Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/ Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 When they click on the flag, the page should put the info into the session, not the URL. Then when you display the prices, if that variable is set, display only one. (Or, display that one much larger, and the others smaller.) Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366584 Share on other sites More sharing options...
Mahngiel Posted August 3, 2012 Share Posted August 3, 2012 didn't i just reply to this? Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366594 Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 There's two. Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366596 Share on other sites More sharing options...
Mal1 Posted August 3, 2012 Author Share Posted August 3, 2012 Sorry, wasn't sure if it was a Javascript issue or CSS (or sessions). I've added a session called currency and defaulted it as GBP. Tried to test using <?php if ($_SESSION['currency'] = 'USD'); ?> (which should not include the code within as the session should = GBP yet it's still showing. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366600 Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 Why should the session = GBP, based on the code you've posted? You've given us one line of code and expect ideas? Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366603 Share on other sites More sharing options...
Mal1 Posted August 3, 2012 Author Share Posted August 3, 2012 Sorry... I have this in my index.php: $_SESSION['currency'] = "GBP"; And then this on the page I want to use it on (I've not added the flags etc. yet to actually change the session info): <?php if ($_SESSION['currency'] = 'USD'); ?> <span> <p class="info">Price:</p> <p class="txt"><strong><?php if ($rug->data['sold']) { ?><p class="price"><?php } ?><?php if ($rug->data['sold']) { ?>Sold</p><?php } else echo '£'.$rug->data['price']; ?></strong></p> </span> <?php if (!$rug->data['sold'] && $rug->data['special_offer']): ?> <span> <p class="info">Now:</p> <p class="now">£<?php echo $rug->data['discount_price']; ?></p> </span> <span> <p class="info">You Save:</p> <p class="price">£<?php echo $rug->data['price'] - $rug->data['discount_price']; ?> (<?php echo round(($rug->data['price'] - $rug->data['discount_price']) / $rug->data['price'] * 100) ?>%)</p> </span> <p> <?php endif; ?> So I was trying to test as it should NOT show the Price data as at this moment $_SESSION['currency'] does not equal "USD". Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366605 Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 In your code you haven't started the session. However, the big problem is you're assigning it as USD, not comparing. http://us2.php.net/manual/en/language.operators.comparison.php Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366606 Share on other sites More sharing options...
Mal1 Posted August 3, 2012 Author Share Posted August 3, 2012 Ah yeah! Thanks, as I said complete newbie at this - I just look at existing code and work things out based on what's already there. Got it working now (the double == and wasn't opening and closing the php if clause the way it was wanting). Just need to add in the code for Euros and Dollars now and put flags on my page and work out how to point them to change the session info to EUR/USD and I'll be done! Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366607 Share on other sites More sharing options...
Mal1 Posted August 4, 2012 Author Share Posted August 4, 2012 I'm now thinking I should have used url variables rather than session variables? I can't seem to figure out how to modify the session variable by clicking on the link/image. I know it's something to do with sessions not being client side... have tried setting the images as forms with hidden post values to no avail.... Any pointers? Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366753 Share on other sites More sharing options...
Jessica Posted August 4, 2012 Share Posted August 4, 2012 Post your updated code. Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1366789 Share on other sites More sharing options...
Mal1 Posted August 8, 2012 Author Share Posted August 8, 2012 Sorry, this has been moved to: http://forums.phpfreaks.com/index.php?topic=363470.0 Quote Link to comment https://forums.phpfreaks.com/topic/266643-switch-currency-divs/#findComment-1367749 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.