Jump to content

WANT HELP WITH CURRENCY CONVERTER


salman233

Recommended Posts

hello everyone i am newbie to php just wanted to make a script for currency converter the problem i am facing is if i want to convert a value from $usd to $euro,$pond,$yen there are three possible values for usd kindly help me out with designing the values for tables and fetching data from them what will be structure of the table what will be the values kindly help me out it,s request thanks

Link to comment
Share on other sites

OK, so I found these sample rates here:  http://www.x-rates.com/

 

You basically need either an array, or a table in mysql to store the conversion rates.  I think an array would work nicely:

$conversions = array(
    'USD'=>1,
    'GBP'=>1.62343,
    'CAD'=>1.02554
);

 

Having that, you then would neet some way to convert the data.  Probably a function:

function br()
{
echo '<br/>';
}
function converter($need, $have, $value, $conversionArray)
{
($conversionArray[$have] / $conversionArray[$need]) * value;
}
var_dump($conversions);
br();
echo converter('USD', 'GBP', 5.25, $conversions);
br();
echo converter('GBP', 'CAD', 5.25, $conversions);

 

Try it and let me know how it works.

 

 

Link to comment
Share on other sites

Sorry, did some error testing at the CLI,

 

This works great:

$conversions = array(
    'USD'=>1,
    'GBP'=>1.62343,
    'CAD'=>1.02554
);
function br()
{
echo '<br/>';
}
function converter($need, $have, $value, $conversionArray)
{
return (($conversionArray[$have] / $conversionArray[$need]) * $value);
}
var_dump($conversions);
br();
echo converter('USD', 'GBP', 5.25, $conversions);
br();
echo converter('GBP', 'USD', 5.25, $conversions);
br();
echo converter('GBP', 'CAD', 5.25, $conversions);

Link to comment
Share on other sites

OK,

 

In the example above we created an 'associative array'.  This basically means that we are identifying the values of the array with 'keys' that contain string values.  IE $conversions['USD'] = 1 in our case above.

 

We created a function that accepts 4 arguments as parameters:

function converter($need, $have, $value, $conversionArray)

$need is the key value we want.

$have is the key value we have.

$value is the amount we have.

$conversionArray is the array containing the Keys / values of our conversions.

 

you can read more at http://www.php.net/manual/en/language.types.array.php,

however I recommend you download the files locally for quicker reference:

http://www.php.net/download-docs.php

 

I have a .chm file on my desktop  :D  I love having it there!

Link to comment
Share on other sites

I hate to be the jerk, but you could do some of the coding. This is the "Help forum", not the "free labor" forum.  If you give us bad code, we will help you fix it -- gladly.  If you tell us to do all the work, you should be in the freelance section.

 

edit Just noticed the freelance section is gone. Smeh. PM someone, and offer to pay them.

Link to comment
Share on other sites

Hey salman, I don't mind being of help.  Jons does have a point though.  Learning these topics will take a lot of time, trial & error, and studying.  You can do it though!

 

I would start off by installing xampp if you haven't already done so,  you can create databases and tables fairly easy with phpmyadmin.

 

Study the mysql functions in the php docs function->database extensions -> mysql reference.

 

Try out some code, read, learn, try some more, when you run into a wall, come back and start a new thread.

 

Good Luck!

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.