Jump to content

Switch currency divs


Mal1

Recommended Posts

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.***

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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?

 

:shrug:

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.