NickG21 Posted December 29, 2006 Share Posted December 29, 2006 below i have my script that i have been working on all day for the currency conversion. it works properly thanks to all the help of the people on these forums, right now it only changes the price of the one value entered into $itemprice. is there anyway i can set this up to be able to change multiple values on one page, since this is going to be a pricing page and there will be much more than just one price on it.[code]<?phpsession_start();if(!isset($_GET["currencyID"])){ $_SESSION["CurrencyID"] = isset($_SESSION["CurrencyID"]) ? $_SESSION["CurrencyID"] : 1;}elseif(isset($_GET["currencyID"])){ if(is_numeric($_GET["currencyID"])) { $_SESSION["CurrencyID"] = $_GET["currencyID"]; }}$CurrencySymbols = array( 1 => "\$", 2 => "€", 3 => "£" );//Examples Made Up$CurrencyExchangeRate = array( 1 => 1, 2 => 0.759594, 3 => 0.510553 );$ItemPrice = 80;$CurrencyPrice = $ItemPrice * $CurrencyExchangeRate[$_SESSION["CurrencyID"]];echo $CurrencySymbols[$_SESSION["CurrencyID"]].$CurrencyPrice;?><html><body><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=1"><img src="./usd.jpg" align="left" border="0" alt="USD" /></a><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=2"><img src="./euro.jpg" align="left" border="0" alt="Euro" /></a><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=3"><img src="./pound.jpg" align="left" border="0" alt="Pound"/></a></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32200-little-help-needed/ Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 Yoo will want to store each item in an array, call this array items. this array will store the item name and price. Then you will want to use a foreach loop to display all the items. Example:[code]<?phpsession_start();function getPrice($price, $dec=2){ if(!isset($_GET["currencyID"])) { $_SESSION["CurrencyID"] = isset($_SESSION["CurrencyID"]) ? $_SESSION["CurrencyID"] : 1; } elseif(isset($_GET["currencyID"])) { if(is_numeric($_GET["currencyID"])) { $_SESSION["CurrencyID"] = $_GET["currencyID"]; } } $CurrencySymbols = array( 1 => "\$", 2 => "€", 3 => "£" ); //Examples Made Up $CurrencyExchangeRate = array( 1 => 1, 2 => 0.759594, 3 => 0.510553 ); $price = $price * $CurrencyExchangeRate[$_SESSION["CurrencyID"]]; $price = number_format($price, $dec); return $CurrencySymbols[$_SESSION["CurrencyID"]].$price;}// Array of items:// item name , price$items= array( array('Candy Cane' , 0.75), array('Ginger Bread' , 2.50), array('Cristmas Cake' , 5.60) );// loop through each item and display price:foreach($items as $item){ echo $item[0] . ' : ' . getPrice($item[1], 2); echo '<br /><br />';}?><html><body>Show prices in:<a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=1"><img src="./usd.jpg" align="left" border="0" alt="USD" /></a><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=2"><img src="./euro.jpg" align="left" border="0" alt="Euro" /></a><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=3"><img src="./pound.jpg" align="left" border="0" alt="Pound"/></a></body></html>[/code]I created a function called getPrice to save having to write out the code in the foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/32200-little-help-needed/#findComment-149549 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.